@rc-component/select 1.6.2 → 1.6.4
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/es/BaseSelect/index.js +13 -7
- package/es/hooks/useOpen.d.ts +1 -1
- package/es/hooks/useOpen.js +1 -1
- package/lib/BaseSelect/index.js +13 -7
- package/lib/hooks/useOpen.d.ts +1 -1
- package/lib/hooks/useOpen.js +1 -1
- package/package.json +1 -1
package/es/BaseSelect/index.js
CHANGED
|
@@ -135,7 +135,7 @@ const BaseSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
135
135
|
// ============================== Open ==============================
|
|
136
136
|
// Not trigger `open` when `notFoundContent` is empty
|
|
137
137
|
const emptyListContent = !notFoundContent && emptyOptions;
|
|
138
|
-
const [mergedOpen, triggerOpen, lockOptions] = useOpen(defaultOpen || false, open, onPopupVisibleChange, nextOpen => disabled || emptyListContent ? false : nextOpen);
|
|
138
|
+
const [rawOpen, mergedOpen, triggerOpen, lockOptions] = useOpen(defaultOpen || false, open, onPopupVisibleChange, nextOpen => disabled || emptyListContent ? false : nextOpen);
|
|
139
139
|
|
|
140
140
|
// ============================= Search =============================
|
|
141
141
|
const tokenWithEnter = React.useMemo(() => (tokenSeparators || []).some(tokenSeparator => ['\n', '\r\n'].includes(tokenSeparator)), [tokenSeparators]);
|
|
@@ -188,12 +188,15 @@ const BaseSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
188
188
|
});
|
|
189
189
|
};
|
|
190
190
|
|
|
191
|
-
//
|
|
191
|
+
// Clean up search value when the dropdown is closed.
|
|
192
|
+
// We use `rawOpen` here to avoid clearing the search input when the dropdown is
|
|
193
|
+
// programmatically closed due to `notFoundContent={null}` and no matching options.
|
|
194
|
+
// This allows the user to continue typing their search query.
|
|
192
195
|
React.useEffect(() => {
|
|
193
|
-
if (!
|
|
196
|
+
if (!rawOpen && !multiple && mode !== 'combobox') {
|
|
194
197
|
onInternalSearch('', false, false);
|
|
195
198
|
}
|
|
196
|
-
}, [
|
|
199
|
+
}, [rawOpen]);
|
|
197
200
|
|
|
198
201
|
// ============================ Disabled ============================
|
|
199
202
|
// Close dropdown & remove focus state when disabled change
|
|
@@ -222,8 +225,11 @@ const BaseSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
222
225
|
key
|
|
223
226
|
} = event;
|
|
224
227
|
const isEnterKey = key === 'Enter';
|
|
225
|
-
|
|
226
|
-
|
|
228
|
+
const isSpaceKey = key === ' ';
|
|
229
|
+
|
|
230
|
+
// Enter or Space opens dropdown (ARIA combobox: spacebar should open)
|
|
231
|
+
if (isEnterKey || isSpaceKey) {
|
|
232
|
+
// Do not submit form when type in the input; prevent Space from scrolling page
|
|
227
233
|
if (mode !== 'combobox') {
|
|
228
234
|
event.preventDefault();
|
|
229
235
|
}
|
|
@@ -254,7 +260,7 @@ const BaseSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
254
260
|
});
|
|
255
261
|
}
|
|
256
262
|
}
|
|
257
|
-
if (mergedOpen && (!isEnterKey || !keyLockRef.current)) {
|
|
263
|
+
if (mergedOpen && (!isEnterKey || !keyLockRef.current) && !isSpaceKey) {
|
|
258
264
|
// Lock the Enter key after it is pressed to avoid repeated triggering of the onChange event.
|
|
259
265
|
if (isEnterKey) {
|
|
260
266
|
keyLockRef.current = true;
|
package/es/hooks/useOpen.d.ts
CHANGED
|
@@ -15,4 +15,4 @@ export type TriggerOpenType = (nextOpen?: boolean, config?: {
|
|
|
15
15
|
* SSR handling: During SSR, `open` is always false to avoid Portal issues.
|
|
16
16
|
* On client-side hydration, it syncs with the actual open state.
|
|
17
17
|
*/
|
|
18
|
-
export default function useOpen(defaultOpen: boolean, propOpen: boolean, onOpen: (nextOpen: boolean) => void, postOpen: (nextOpen: boolean) => boolean): [open: boolean, toggleOpen: TriggerOpenType, lockOptions: boolean];
|
|
18
|
+
export default function useOpen(defaultOpen: boolean, propOpen: boolean, onOpen: (nextOpen: boolean) => void, postOpen: (nextOpen: boolean) => boolean): [rawOpen: boolean, open: boolean, toggleOpen: TriggerOpenType, lockOptions: boolean];
|
package/es/hooks/useOpen.js
CHANGED
package/lib/BaseSelect/index.js
CHANGED
|
@@ -144,7 +144,7 @@ const BaseSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
144
144
|
// ============================== Open ==============================
|
|
145
145
|
// Not trigger `open` when `notFoundContent` is empty
|
|
146
146
|
const emptyListContent = !notFoundContent && emptyOptions;
|
|
147
|
-
const [mergedOpen, triggerOpen, lockOptions] = (0, _useOpen.default)(defaultOpen || false, open, onPopupVisibleChange, nextOpen => disabled || emptyListContent ? false : nextOpen);
|
|
147
|
+
const [rawOpen, mergedOpen, triggerOpen, lockOptions] = (0, _useOpen.default)(defaultOpen || false, open, onPopupVisibleChange, nextOpen => disabled || emptyListContent ? false : nextOpen);
|
|
148
148
|
|
|
149
149
|
// ============================= Search =============================
|
|
150
150
|
const tokenWithEnter = React.useMemo(() => (tokenSeparators || []).some(tokenSeparator => ['\n', '\r\n'].includes(tokenSeparator)), [tokenSeparators]);
|
|
@@ -197,12 +197,15 @@ const BaseSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
197
197
|
});
|
|
198
198
|
};
|
|
199
199
|
|
|
200
|
-
//
|
|
200
|
+
// Clean up search value when the dropdown is closed.
|
|
201
|
+
// We use `rawOpen` here to avoid clearing the search input when the dropdown is
|
|
202
|
+
// programmatically closed due to `notFoundContent={null}` and no matching options.
|
|
203
|
+
// This allows the user to continue typing their search query.
|
|
201
204
|
React.useEffect(() => {
|
|
202
|
-
if (!
|
|
205
|
+
if (!rawOpen && !multiple && mode !== 'combobox') {
|
|
203
206
|
onInternalSearch('', false, false);
|
|
204
207
|
}
|
|
205
|
-
}, [
|
|
208
|
+
}, [rawOpen]);
|
|
206
209
|
|
|
207
210
|
// ============================ Disabled ============================
|
|
208
211
|
// Close dropdown & remove focus state when disabled change
|
|
@@ -231,8 +234,11 @@ const BaseSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
231
234
|
key
|
|
232
235
|
} = event;
|
|
233
236
|
const isEnterKey = key === 'Enter';
|
|
234
|
-
|
|
235
|
-
|
|
237
|
+
const isSpaceKey = key === ' ';
|
|
238
|
+
|
|
239
|
+
// Enter or Space opens dropdown (ARIA combobox: spacebar should open)
|
|
240
|
+
if (isEnterKey || isSpaceKey) {
|
|
241
|
+
// Do not submit form when type in the input; prevent Space from scrolling page
|
|
236
242
|
if (mode !== 'combobox') {
|
|
237
243
|
event.preventDefault();
|
|
238
244
|
}
|
|
@@ -263,7 +269,7 @@ const BaseSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
263
269
|
});
|
|
264
270
|
}
|
|
265
271
|
}
|
|
266
|
-
if (mergedOpen && (!isEnterKey || !keyLockRef.current)) {
|
|
272
|
+
if (mergedOpen && (!isEnterKey || !keyLockRef.current) && !isSpaceKey) {
|
|
267
273
|
// Lock the Enter key after it is pressed to avoid repeated triggering of the onChange event.
|
|
268
274
|
if (isEnterKey) {
|
|
269
275
|
keyLockRef.current = true;
|
package/lib/hooks/useOpen.d.ts
CHANGED
|
@@ -15,4 +15,4 @@ export type TriggerOpenType = (nextOpen?: boolean, config?: {
|
|
|
15
15
|
* SSR handling: During SSR, `open` is always false to avoid Portal issues.
|
|
16
16
|
* On client-side hydration, it syncs with the actual open state.
|
|
17
17
|
*/
|
|
18
|
-
export default function useOpen(defaultOpen: boolean, propOpen: boolean, onOpen: (nextOpen: boolean) => void, postOpen: (nextOpen: boolean) => boolean): [open: boolean, toggleOpen: TriggerOpenType, lockOptions: boolean];
|
|
18
|
+
export default function useOpen(defaultOpen: boolean, propOpen: boolean, onOpen: (nextOpen: boolean) => void, postOpen: (nextOpen: boolean) => boolean): [rawOpen: boolean, open: boolean, toggleOpen: TriggerOpenType, lockOptions: boolean];
|
package/lib/hooks/useOpen.js
CHANGED