antd-mobile 5.41.1 → 5.42.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/2x/bundle/antd-mobile.cjs.development.js +80 -59
  2. package/2x/bundle/antd-mobile.cjs.js +6 -6
  3. package/2x/bundle/antd-mobile.es.development.js +80 -59
  4. package/2x/bundle/antd-mobile.es.js +1743 -1729
  5. package/2x/bundle/antd-mobile.umd.development.js +80 -59
  6. package/2x/bundle/antd-mobile.umd.js +6 -6
  7. package/2x/bundle/style.css +9 -2
  8. package/2x/cjs/components/dialog/dialog.d.ts +2 -2
  9. package/2x/cjs/components/dialog/dialog.js +3 -3
  10. package/2x/cjs/components/modal/modal.d.ts +2 -2
  11. package/2x/cjs/components/modal/modal.js +4 -4
  12. package/2x/cjs/components/number-keyboard/number-keyboard.d.ts +6 -1
  13. package/2x/cjs/components/number-keyboard/number-keyboard.js +33 -29
  14. package/2x/cjs/components/virtual-input/use-click-outside.d.ts +2 -0
  15. package/2x/cjs/components/virtual-input/use-click-outside.js +25 -0
  16. package/2x/cjs/components/virtual-input/virtual-input.css +9 -2
  17. package/2x/cjs/components/virtual-input/virtual-input.js +32 -30
  18. package/2x/es/components/dialog/dialog.d.ts +2 -2
  19. package/2x/es/components/dialog/dialog.js +3 -3
  20. package/2x/es/components/modal/modal.d.ts +2 -2
  21. package/2x/es/components/modal/modal.js +4 -4
  22. package/2x/es/components/number-keyboard/number-keyboard.d.ts +6 -1
  23. package/2x/es/components/number-keyboard/number-keyboard.js +33 -29
  24. package/2x/es/components/virtual-input/use-click-outside.d.ts +2 -0
  25. package/2x/es/components/virtual-input/use-click-outside.js +18 -0
  26. package/2x/es/components/virtual-input/virtual-input.css +9 -2
  27. package/2x/es/components/virtual-input/virtual-input.js +32 -30
  28. package/2x/package.json +1 -1
  29. package/bundle/antd-mobile.cjs.development.js +80 -59
  30. package/bundle/antd-mobile.cjs.js +6 -6
  31. package/bundle/antd-mobile.compatible.umd.js +1 -1
  32. package/bundle/antd-mobile.es.development.js +80 -59
  33. package/bundle/antd-mobile.es.js +1743 -1729
  34. package/bundle/antd-mobile.umd.development.js +80 -59
  35. package/bundle/antd-mobile.umd.js +6 -6
  36. package/bundle/style.css +1 -1
  37. package/cjs/components/dialog/dialog.d.ts +2 -2
  38. package/cjs/components/dialog/dialog.js +3 -3
  39. package/cjs/components/modal/modal.d.ts +2 -2
  40. package/cjs/components/modal/modal.js +4 -4
  41. package/cjs/components/number-keyboard/number-keyboard.d.ts +6 -1
  42. package/cjs/components/number-keyboard/number-keyboard.js +33 -29
  43. package/cjs/components/virtual-input/use-click-outside.d.ts +2 -0
  44. package/cjs/components/virtual-input/use-click-outside.js +25 -0
  45. package/cjs/components/virtual-input/virtual-input.css +8 -2
  46. package/cjs/components/virtual-input/virtual-input.js +32 -30
  47. package/es/components/dialog/dialog.d.ts +2 -2
  48. package/es/components/dialog/dialog.js +3 -3
  49. package/es/components/modal/modal.d.ts +2 -2
  50. package/es/components/modal/modal.js +4 -4
  51. package/es/components/number-keyboard/number-keyboard.d.ts +6 -1
  52. package/es/components/number-keyboard/number-keyboard.js +33 -29
  53. package/es/components/virtual-input/use-click-outside.d.ts +2 -0
  54. package/es/components/virtual-input/use-click-outside.js +18 -0
  55. package/es/components/virtual-input/virtual-input.css +8 -2
  56. package/es/components/virtual-input/virtual-input.js +32 -30
  57. package/package.json +1 -1
  58. package/umd/antd-mobile.js +1 -1
@@ -23189,7 +23189,6 @@ const NumberKeyboard = (p) => {
23189
23189
  };
23190
23190
  const onKeyPress = (e2, key) => {
23191
23191
  var _a, _b;
23192
- e2.preventDefault();
23193
23192
  switch (key) {
23194
23193
  case "BACKSPACE":
23195
23194
  onDelete === null || onDelete === void 0 ? void 0 : onDelete();
@@ -23227,39 +23226,51 @@ const NumberKeyboard = (p) => {
23227
23226
  tabIndex: -1
23228
23227
  }, React__default.createElement(DownOutline, null)));
23229
23228
  };
23229
+ const onBackspaceTouchStart = () => {
23230
+ stopContinueClear();
23231
+ startContinueClear();
23232
+ };
23233
+ const onBackspaceTouchEnd = (e2) => {
23234
+ e2.preventDefault();
23235
+ stopContinueClear();
23236
+ onKeyPress(e2, "BACKSPACE");
23237
+ };
23230
23238
  const renderKey = (key, index2) => {
23231
- const isNumberKey = /^\d$/.test(key);
23232
- const isBackspace = key === "BACKSPACE";
23239
+ const keyConfig = typeof key === "string" ? {
23240
+ key,
23241
+ title: key
23242
+ } : key;
23243
+ const realKey = keyConfig.key;
23244
+ const isNumberKey = /^\d$/.test(realKey);
23245
+ const isBackspace = realKey === "BACKSPACE";
23246
+ const title2 = isBackspace ? locale.Input.clear : keyConfig.title;
23233
23247
  const className = classNames(`${classPrefix$x}-key`, {
23234
23248
  [`${classPrefix$x}-key-number`]: isNumberKey,
23235
- [`${classPrefix$x}-key-sign`]: !isNumberKey && key,
23249
+ [`${classPrefix$x}-key-sign`]: !isNumberKey && realKey,
23236
23250
  [`${classPrefix$x}-key-mid`]: index2 === 9 && !!confirmText && keys2.length < 12
23237
23251
  });
23238
- const ariaProps = key ? {
23252
+ const ariaProps = realKey ? {
23239
23253
  role: "button",
23240
- title: isBackspace ? locale.Input.clear : key,
23254
+ title: title2,
23255
+ "aria-label": title2,
23241
23256
  tabIndex: -1
23242
23257
  } : void 0;
23243
23258
  return React__default.createElement("div", Object.assign({
23244
- key,
23259
+ key: realKey,
23245
23260
  className,
23246
23261
  // 仅为 backspace 绑定,支持长按快速删除
23247
- onTouchStart: isBackspace ? () => {
23248
- stopContinueClear();
23249
- startContinueClear();
23250
- } : void 0,
23251
- onTouchEnd: isBackspace ? (e2) => {
23252
- stopContinueClear();
23253
- onKeyPress(e2, key);
23254
- } : void 0,
23262
+ onTouchStart: isBackspace ? onBackspaceTouchStart : void 0,
23263
+ onTouchEnd: isBackspace ? onBackspaceTouchEnd : void 0,
23264
+ onTouchCancel: isBackspace ? stopContinueClear : void 0,
23255
23265
  // <div role="button" title="1" onTouchEnd={e => {}}>1</div> 安卓上 talback 可读不可点
23256
23266
  // see https://ua-gilded-eef7f9.netlify.app/grid-button-bug.html
23257
- // 所以还是绑定 click,通过 touchEnd preventDefault 防重复触发
23267
+ // 所以普通按钮绑定 click 事件,而 backspace 仍然额外绑定 touch 事件支持长按删除
23268
+ // backspace touchend 时会 preventDefault 阻止其后续 click 事件
23258
23269
  onClick: (e2) => {
23259
23270
  stopContinueClear();
23260
- onKeyPress(e2, key);
23271
+ onKeyPress(e2, realKey);
23261
23272
  }
23262
- }, ariaProps), isBackspace ? React__default.createElement(TextDeletionOutline, null) : key);
23273
+ }, ariaProps), isBackspace ? React__default.createElement(TextDeletionOutline, null) : realKey);
23263
23274
  };
23264
23275
  return React__default.createElement(Popup, {
23265
23276
  visible,
@@ -23273,10 +23284,7 @@ const NumberKeyboard = (p) => {
23273
23284
  forceRender: props.forceRender
23274
23285
  }, withNativeProps(props, React__default.createElement("div", {
23275
23286
  ref: keyboardRef,
23276
- className: classPrefix$x,
23277
- onMouseDown: (e2) => {
23278
- e2.preventDefault();
23279
- }
23287
+ className: classPrefix$x
23280
23288
  }, renderHeader(), React__default.createElement("div", {
23281
23289
  className: `${classPrefix$x}-wrapper`
23282
23290
  }, React__default.createElement("div", {
@@ -23287,13 +23295,9 @@ const NumberKeyboard = (p) => {
23287
23295
  className: `${classPrefix$x}-confirm`
23288
23296
  }, React__default.createElement("div", {
23289
23297
  className: `${classPrefix$x}-key ${classPrefix$x}-key-extra ${classPrefix$x}-key-bs`,
23290
- onTouchStart: () => {
23291
- startContinueClear();
23292
- },
23293
- onTouchEnd: (e2) => {
23294
- stopContinueClear();
23295
- onKeyPress(e2, "BACKSPACE");
23296
- },
23298
+ onTouchStart: onBackspaceTouchStart,
23299
+ onTouchEnd: onBackspaceTouchEnd,
23300
+ onTouchCancel: stopContinueClear,
23297
23301
  onClick: (e2) => {
23298
23302
  stopContinueClear();
23299
23303
  onKeyPress(e2, "BACKSPACE");
@@ -27577,6 +27581,20 @@ const Multiple = (p) => {
27577
27581
  const index = attachPropertiesToComponent(TreeSelect, {
27578
27582
  Multiple
27579
27583
  });
27584
+ function useClickOutside(handler, ref2) {
27585
+ useEffect(() => {
27586
+ function handleClick(event) {
27587
+ if (!ref2.current || ref2.current.contains(event.target)) {
27588
+ return;
27589
+ }
27590
+ handler(event);
27591
+ }
27592
+ document.addEventListener("click", handleClick, true);
27593
+ return () => {
27594
+ document.removeEventListener("click", handleClick, true);
27595
+ };
27596
+ }, [handler, ref2]);
27597
+ }
27580
27598
  const classPrefix$2 = "adm-virtual-input";
27581
27599
  const defaultProps$2 = {
27582
27600
  defaultValue: "",
@@ -27604,15 +27622,10 @@ const VirtualInput = forwardRef((props, ref2) => {
27604
27622
  const touchMoveTimeoutRef = useRef();
27605
27623
  const clearIcon = mergeProp(React__default.createElement(CloseCircleFill, null), componentConfig.clearIcon, props.clearIcon);
27606
27624
  function scrollToEnd() {
27607
- const root2 = rootRef.current;
27608
- if (!root2)
27609
- return;
27610
- if (document.activeElement !== root2) {
27611
- return;
27612
- }
27613
27625
  const content = contentRef.current;
27614
- if (!content)
27626
+ if (!content) {
27615
27627
  return;
27628
+ }
27616
27629
  content.scrollLeft = content.clientWidth;
27617
27630
  }
27618
27631
  useEffect(() => {
@@ -27642,23 +27655,31 @@ const VirtualInput = forwardRef((props, ref2) => {
27642
27655
  useImperativeHandle(ref2, () => ({
27643
27656
  focus: () => {
27644
27657
  var _a;
27645
- (_a = rootRef.current) === null || _a === void 0 ? void 0 : _a.focus();
27658
+ (_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.focus();
27646
27659
  },
27647
27660
  blur: () => {
27648
27661
  var _a;
27649
- (_a = rootRef.current) === null || _a === void 0 ? void 0 : _a.blur();
27662
+ (_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.blur();
27663
+ setBlur();
27650
27664
  }
27651
27665
  }));
27652
- function onFocus() {
27666
+ function setFocus() {
27653
27667
  var _a;
27668
+ if (hasFocus)
27669
+ return;
27654
27670
  setHasFocus(true);
27655
27671
  (_a = mergedProps.onFocus) === null || _a === void 0 ? void 0 : _a.call(mergedProps);
27656
27672
  }
27657
- function onBlur() {
27673
+ function setBlur() {
27658
27674
  var _a;
27675
+ if (!hasFocus)
27676
+ return;
27659
27677
  setHasFocus(false);
27660
27678
  (_a = mergedProps.onBlur) === null || _a === void 0 ? void 0 : _a.call(mergedProps);
27661
27679
  }
27680
+ useClickOutside(() => {
27681
+ setBlur();
27682
+ }, rootRef);
27662
27683
  const keyboard = mergedProps.keyboard;
27663
27684
  const keyboardElement = keyboard && React__default.cloneElement(keyboard, {
27664
27685
  onInput: (v) => {
@@ -27685,23 +27706,19 @@ const VirtualInput = forwardRef((props, ref2) => {
27685
27706
  },
27686
27707
  visible: hasFocus,
27687
27708
  onClose: () => {
27688
- var _a, _b, _c, _d;
27689
- const activeElement = document.activeElement;
27690
- if (activeElement && ((_a = rootRef.current) === null || _a === void 0 ? void 0 : _a.contains(activeElement))) {
27691
- activeElement.blur();
27692
- } else {
27693
- (_b = rootRef.current) === null || _b === void 0 ? void 0 : _b.blur();
27694
- }
27695
- (_d = (_c = keyboard.props).onClose) === null || _d === void 0 ? void 0 : _d.call(_c);
27709
+ var _a, _b;
27710
+ setBlur();
27711
+ (_b = (_a = keyboard.props).onClose) === null || _b === void 0 ? void 0 : _b.call(_a);
27696
27712
  },
27697
27713
  getContainer: null
27698
27714
  });
27699
- const setCaretPositionToEnd = () => {
27700
- var _a, _b;
27715
+ const setCaretPositionToEnd = (e2) => {
27716
+ var _a, _b, _c;
27701
27717
  if (caretPosition !== value.length) {
27702
27718
  setCaretPosition(value.length);
27703
27719
  (_b = (_a = mergedProps.cursor) === null || _a === void 0 ? void 0 : _a.onMove) === null || _b === void 0 ? void 0 : _b.call(_a, value.length);
27704
27720
  }
27721
+ (_c = mergedProps.onClick) === null || _c === void 0 ? void 0 : _c.call(mergedProps, e2);
27705
27722
  };
27706
27723
  const changeCaretPosition = (index2) => (e2) => {
27707
27724
  var _a, _b, _c;
@@ -27768,23 +27785,27 @@ const VirtualInput = forwardRef((props, ref2) => {
27768
27785
  ref: rootRef,
27769
27786
  className: classNames(classPrefix$2, {
27770
27787
  [`${classPrefix$2}-disabled`]: mergedProps.disabled,
27771
- [`${classPrefix$2}-caret-dragging`]: isCaretDragging
27772
- }),
27773
- tabIndex: mergedProps.disabled ? void 0 : 0,
27774
- role: "textbox",
27775
- onFocus,
27776
- onBlur,
27777
- onClick: mergedProps.onClick
27788
+ [`${classPrefix$2}-caret-dragging`]: isCaretDragging,
27789
+ [`${classPrefix$2}-focused`]: hasFocus
27790
+ })
27778
27791
  }, React__default.createElement("div", {
27779
27792
  className: `${classPrefix$2}-content`,
27780
27793
  ref: contentRef,
27781
27794
  "aria-disabled": mergedProps.disabled,
27782
- "aria-label": mergedProps.placeholder,
27795
+ "aria-label": value || mergedProps.placeholder,
27796
+ role: "textbox",
27797
+ tabIndex: mergedProps.disabled ? void 0 : 0,
27798
+ // note: 这里增加 onFocus 有两个目的:
27799
+ // 1. 在安卓 talkback 模式下,role=textbox 的元素双击后只会触发 focus 而非 click
27800
+ // 2. 处理 content 框点击、单个字符点击时,不用再额外处理 focus 逻辑,因为 focus 事件会先触发
27801
+ onFocus: setFocus,
27783
27802
  onClick: setCaretPositionToEnd,
27784
27803
  onTouchStart: handleTouchStart,
27785
27804
  onTouchMove: handleTouchMove,
27786
27805
  onTouchEnd: handleTouchEnd
27787
- }, chars.slice(0, caretPosition).map((i2, index2) => React__default.createElement("span", {
27806
+ }, React__default.createElement("span", {
27807
+ className: `${classPrefix$2}-trap`
27808
+ }), chars.slice(0, caretPosition).map((i2, index2) => React__default.createElement("span", {
27788
27809
  ref: index2 === 0 ? charRef : void 0,
27789
27810
  key: index2,
27790
27811
  onClick: changeCaretPosition(index2)