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.
- package/2x/bundle/antd-mobile.cjs.development.js +80 -59
- package/2x/bundle/antd-mobile.cjs.js +6 -6
- package/2x/bundle/antd-mobile.es.development.js +80 -59
- package/2x/bundle/antd-mobile.es.js +1743 -1729
- package/2x/bundle/antd-mobile.umd.development.js +80 -59
- package/2x/bundle/antd-mobile.umd.js +6 -6
- package/2x/bundle/style.css +9 -2
- package/2x/cjs/components/dialog/dialog.d.ts +2 -2
- package/2x/cjs/components/dialog/dialog.js +3 -3
- package/2x/cjs/components/modal/modal.d.ts +2 -2
- package/2x/cjs/components/modal/modal.js +4 -4
- package/2x/cjs/components/number-keyboard/number-keyboard.d.ts +6 -1
- package/2x/cjs/components/number-keyboard/number-keyboard.js +33 -29
- package/2x/cjs/components/virtual-input/use-click-outside.d.ts +2 -0
- package/2x/cjs/components/virtual-input/use-click-outside.js +25 -0
- package/2x/cjs/components/virtual-input/virtual-input.css +9 -2
- package/2x/cjs/components/virtual-input/virtual-input.js +32 -30
- package/2x/es/components/dialog/dialog.d.ts +2 -2
- package/2x/es/components/dialog/dialog.js +3 -3
- package/2x/es/components/modal/modal.d.ts +2 -2
- package/2x/es/components/modal/modal.js +4 -4
- package/2x/es/components/number-keyboard/number-keyboard.d.ts +6 -1
- package/2x/es/components/number-keyboard/number-keyboard.js +33 -29
- package/2x/es/components/virtual-input/use-click-outside.d.ts +2 -0
- package/2x/es/components/virtual-input/use-click-outside.js +18 -0
- package/2x/es/components/virtual-input/virtual-input.css +9 -2
- package/2x/es/components/virtual-input/virtual-input.js +32 -30
- package/2x/package.json +1 -1
- package/bundle/antd-mobile.cjs.development.js +80 -59
- package/bundle/antd-mobile.cjs.js +6 -6
- package/bundle/antd-mobile.compatible.umd.js +1 -1
- package/bundle/antd-mobile.es.development.js +80 -59
- package/bundle/antd-mobile.es.js +1743 -1729
- package/bundle/antd-mobile.umd.development.js +80 -59
- package/bundle/antd-mobile.umd.js +6 -6
- package/bundle/style.css +1 -1
- package/cjs/components/dialog/dialog.d.ts +2 -2
- package/cjs/components/dialog/dialog.js +3 -3
- package/cjs/components/modal/modal.d.ts +2 -2
- package/cjs/components/modal/modal.js +4 -4
- package/cjs/components/number-keyboard/number-keyboard.d.ts +6 -1
- package/cjs/components/number-keyboard/number-keyboard.js +33 -29
- package/cjs/components/virtual-input/use-click-outside.d.ts +2 -0
- package/cjs/components/virtual-input/use-click-outside.js +25 -0
- package/cjs/components/virtual-input/virtual-input.css +8 -2
- package/cjs/components/virtual-input/virtual-input.js +32 -30
- package/es/components/dialog/dialog.d.ts +2 -2
- package/es/components/dialog/dialog.js +3 -3
- package/es/components/modal/modal.d.ts +2 -2
- package/es/components/modal/modal.js +4 -4
- package/es/components/number-keyboard/number-keyboard.d.ts +6 -1
- package/es/components/number-keyboard/number-keyboard.js +33 -29
- package/es/components/virtual-input/use-click-outside.d.ts +2 -0
- package/es/components/virtual-input/use-click-outside.js +18 -0
- package/es/components/virtual-input/virtual-input.css +8 -2
- package/es/components/virtual-input/virtual-input.js +32 -30
- package/package.json +1 -1
- 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
|
|
37
|
-
if (!
|
|
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 =
|
|
72
|
+
(_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
75
73
|
},
|
|
76
74
|
blur: () => {
|
|
77
75
|
var _a;
|
|
78
|
-
(_a =
|
|
76
|
+
(_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
77
|
+
setBlur();
|
|
79
78
|
}
|
|
80
79
|
}));
|
|
81
|
-
function
|
|
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
|
|
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
|
|
119
|
-
|
|
120
|
-
|
|
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
|
-
|
|
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
|
-
},
|
|
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)
|