@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.
@@ -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
- // Close will clean up single mode search text
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 (!mergedOpen && !multiple && mode !== 'combobox') {
196
+ if (!rawOpen && !multiple && mode !== 'combobox') {
194
197
  onInternalSearch('', false, false);
195
198
  }
196
- }, [mergedOpen]);
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
- if (isEnterKey) {
226
- // Do not submit form when type in the input
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;
@@ -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];
@@ -78,5 +78,5 @@ export default function useOpen(defaultOpen, propOpen, onOpen, postOpen) {
78
78
  });
79
79
  }
80
80
  });
81
- return [mergedOpen, toggleOpen, lock];
81
+ return [ssrSafeOpen, mergedOpen, toggleOpen, lock];
82
82
  }
@@ -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
- // Close will clean up single mode search text
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 (!mergedOpen && !multiple && mode !== 'combobox') {
205
+ if (!rawOpen && !multiple && mode !== 'combobox') {
203
206
  onInternalSearch('', false, false);
204
207
  }
205
- }, [mergedOpen]);
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
- if (isEnterKey) {
235
- // Do not submit form when type in the input
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;
@@ -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];
@@ -85,5 +85,5 @@ function useOpen(defaultOpen, propOpen, onOpen, postOpen) {
85
85
  });
86
86
  }
87
87
  });
88
- return [mergedOpen, toggleOpen, lock];
88
+ return [ssrSafeOpen, mergedOpen, toggleOpen, lock];
89
89
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rc-component/select",
3
- "version": "1.6.2",
3
+ "version": "1.6.4",
4
4
  "description": "React Select",
5
5
  "engines": {
6
6
  "node": ">=8.x"