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
@@ -6,6 +6,7 @@ import { withNativeProps } from '../../utils/native-props';
6
6
  import { usePropsValue } from '../../utils/use-props-value';
7
7
  import { mergeProp, mergeProps } from '../../utils/with-default-props';
8
8
  import { useConfig } from '../config-provider';
9
+ import useClickOutside from './use-click-outside';
9
10
  const classPrefix = 'adm-virtual-input';
10
11
  const defaultProps = {
11
12
  defaultValue: '',
@@ -33,13 +34,10 @@ export const VirtualInput = forwardRef((props, ref) => {
33
34
  const touchMoveTimeoutRef = useRef();
34
35
  const clearIcon = mergeProp(React.createElement(CloseCircleFill, null), componentConfig.clearIcon, props.clearIcon);
35
36
  function scrollToEnd() {
36
- const root = rootRef.current;
37
- if (!root) return;
38
- if (document.activeElement !== root) {
37
+ const content = contentRef.current;
38
+ if (!content) {
39
39
  return;
40
40
  }
41
- const content = contentRef.current;
42
- if (!content) return;
43
41
  content.scrollLeft = content.clientWidth;
44
42
  }
45
43
  useEffect(() => {
@@ -71,23 +69,29 @@ export const VirtualInput = forwardRef((props, ref) => {
71
69
  useImperativeHandle(ref, () => ({
72
70
  focus: () => {
73
71
  var _a;
74
- (_a = rootRef.current) === null || _a === void 0 ? void 0 : _a.focus();
72
+ (_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.focus();
75
73
  },
76
74
  blur: () => {
77
75
  var _a;
78
- (_a = rootRef.current) === null || _a === void 0 ? void 0 : _a.blur();
76
+ (_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.blur();
77
+ setBlur();
79
78
  }
80
79
  }));
81
- function onFocus() {
80
+ function setFocus() {
82
81
  var _a;
82
+ if (hasFocus) return;
83
83
  setHasFocus(true);
84
84
  (_a = mergedProps.onFocus) === null || _a === void 0 ? void 0 : _a.call(mergedProps);
85
85
  }
86
- function onBlur() {
86
+ function setBlur() {
87
87
  var _a;
88
+ if (!hasFocus) return;
88
89
  setHasFocus(false);
89
90
  (_a = mergedProps.onBlur) === null || _a === void 0 ? void 0 : _a.call(mergedProps);
90
91
  }
92
+ useClickOutside(() => {
93
+ setBlur();
94
+ }, rootRef);
91
95
  const keyboard = mergedProps.keyboard;
92
96
  const keyboardElement = keyboard && React.cloneElement(keyboard, {
93
97
  onInput: v => {
@@ -115,26 +119,20 @@ export const VirtualInput = forwardRef((props, ref) => {
115
119
  },
116
120
  visible: hasFocus,
117
121
  onClose: () => {
118
- var _a, _b, _c, _d;
119
- const activeElement = document.activeElement;
120
- // Long press makes `activeElement` to be the child of rootRef
121
- // We will trigger blur on the child element instead
122
- if (activeElement && ((_a = rootRef.current) === null || _a === void 0 ? void 0 : _a.contains(activeElement))) {
123
- activeElement.blur();
124
- } else {
125
- (_b = rootRef.current) === null || _b === void 0 ? void 0 : _b.blur();
126
- }
127
- (_d = (_c = keyboard.props).onClose) === null || _d === void 0 ? void 0 : _d.call(_c);
122
+ var _a, _b;
123
+ setBlur();
124
+ (_b = (_a = keyboard.props).onClose) === null || _b === void 0 ? void 0 : _b.call(_a);
128
125
  },
129
126
  getContainer: null
130
127
  });
131
128
  // 点击输入框时,将光标置于最后
132
- const setCaretPositionToEnd = () => {
133
- var _a, _b;
129
+ const setCaretPositionToEnd = e => {
130
+ var _a, _b, _c;
134
131
  if (caretPosition !== value.length) {
135
132
  setCaretPosition(value.length);
136
133
  (_b = (_a = mergedProps.cursor) === null || _a === void 0 ? void 0 : _a.onMove) === null || _b === void 0 ? void 0 : _b.call(_a, value.length);
137
134
  }
135
+ (_c = mergedProps.onClick) === null || _c === void 0 ? void 0 : _c.call(mergedProps, e);
138
136
  };
139
137
  // 点击单个字符时,根据点击位置置于字符前或后
140
138
  const changeCaretPosition = index => e => {
@@ -203,23 +201,27 @@ export const VirtualInput = forwardRef((props, ref) => {
203
201
  ref: rootRef,
204
202
  className: classNames(classPrefix, {
205
203
  [`${classPrefix}-disabled`]: mergedProps.disabled,
206
- [`${classPrefix}-caret-dragging`]: isCaretDragging
207
- }),
208
- tabIndex: mergedProps.disabled ? undefined : 0,
209
- role: 'textbox',
210
- onFocus: onFocus,
211
- onBlur: onBlur,
212
- onClick: mergedProps.onClick
204
+ [`${classPrefix}-caret-dragging`]: isCaretDragging,
205
+ [`${classPrefix}-focused`]: hasFocus
206
+ })
213
207
  }, React.createElement("div", {
214
208
  className: `${classPrefix}-content`,
215
209
  ref: contentRef,
216
210
  "aria-disabled": mergedProps.disabled,
217
- "aria-label": mergedProps.placeholder,
211
+ "aria-label": value || mergedProps.placeholder,
212
+ role: 'textbox',
213
+ tabIndex: mergedProps.disabled ? undefined : 0,
214
+ // note: 这里增加 onFocus 有两个目的:
215
+ // 1. 在安卓 talkback 模式下,role=textbox 的元素双击后只会触发 focus 而非 click
216
+ // 2. 处理 content 框点击、单个字符点击时,不用再额外处理 focus 逻辑,因为 focus 事件会先触发
217
+ onFocus: setFocus,
218
218
  onClick: setCaretPositionToEnd,
219
219
  onTouchStart: handleTouchStart,
220
220
  onTouchMove: handleTouchMove,
221
221
  onTouchEnd: handleTouchEnd
222
- }, chars.slice(0, caretPosition).map((i, index) => React.createElement("span", {
222
+ }, React.createElement("span", {
223
+ className: `${classPrefix}-trap`
224
+ }), chars.slice(0, caretPosition).map((i, index) => React.createElement("span", {
223
225
  ref: index === 0 ? charRef : undefined,
224
226
  key: index,
225
227
  onClick: changeCaretPosition(index)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "antd-mobile",
3
- "version": "5.41.1",
3
+ "version": "5.42.0-alpha.1",
4
4
  "homepage": "https://github.com/ant-design/ant-design-mobile#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/ant-design/ant-design-mobile/issues"