@rc-component/select 1.6.3 → 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
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
|
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
|
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