@rc-component/select 1.6.3 → 1.6.5
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 +9 -5
- package/es/SelectInput/Content/MultipleContent.js +3 -1
- package/es/hooks/useBaseProps.d.ts +1 -0
- package/es/hooks/useOpen.d.ts +1 -1
- package/es/hooks/useOpen.js +1 -1
- package/lib/BaseSelect/index.js +9 -5
- package/lib/SelectInput/Content/MultipleContent.js +3 -1
- package/lib/hooks/useBaseProps.d.ts +1 -0
- 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
|
|
@@ -376,6 +379,7 @@ const BaseSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
376
379
|
notFoundContent,
|
|
377
380
|
open: mergedOpen,
|
|
378
381
|
triggerOpen: mergedOpen,
|
|
382
|
+
rawOpen,
|
|
379
383
|
id,
|
|
380
384
|
showSearch,
|
|
381
385
|
multiple,
|
|
@@ -384,7 +388,7 @@ const BaseSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
384
388
|
styles,
|
|
385
389
|
classNames,
|
|
386
390
|
lockOptions
|
|
387
|
-
}), [props, notFoundContent, triggerOpen, id, showSearch, multiple, mergedOpen, showScrollBar, styles, classNames, lockOptions]);
|
|
391
|
+
}), [props, notFoundContent, triggerOpen, id, showSearch, multiple, mergedOpen, rawOpen, showScrollBar, styles, classNames, lockOptions]);
|
|
388
392
|
|
|
389
393
|
// ==================================================================
|
|
390
394
|
// == Render ==
|
|
@@ -30,6 +30,7 @@ export default /*#__PURE__*/React.forwardRef(function MultipleContent({
|
|
|
30
30
|
disabled,
|
|
31
31
|
showSearch,
|
|
32
32
|
triggerOpen,
|
|
33
|
+
rawOpen,
|
|
33
34
|
toggleOpen,
|
|
34
35
|
autoClearSearchValue,
|
|
35
36
|
tagRender: tagRenderFromContext,
|
|
@@ -43,8 +44,9 @@ export default /*#__PURE__*/React.forwardRef(function MultipleContent({
|
|
|
43
44
|
|
|
44
45
|
// ===================== Search ======================
|
|
45
46
|
// Apply autoClearSearchValue logic: when dropdown is closed and autoClearSearchValue is not false (default true), clear search value
|
|
47
|
+
// Use rawOpen to avoid clearing search when emptyListContent blocks open
|
|
46
48
|
let computedSearchValue = searchValue;
|
|
47
|
-
if (!
|
|
49
|
+
if (!rawOpen && mode === 'multiple' && autoClearSearchValue !== false) {
|
|
48
50
|
computedSearchValue = '';
|
|
49
51
|
}
|
|
50
52
|
const inputValue = showSearch ? computedSearchValue || '' : '';
|
|
@@ -6,6 +6,7 @@ import * as React from 'react';
|
|
|
6
6
|
import type { BaseSelectProps } from '../BaseSelect';
|
|
7
7
|
export interface BaseSelectContextProps extends BaseSelectProps {
|
|
8
8
|
triggerOpen: boolean;
|
|
9
|
+
rawOpen: boolean;
|
|
9
10
|
multiple: boolean;
|
|
10
11
|
toggleOpen: (open?: boolean) => void;
|
|
11
12
|
lockOptions: boolean;
|
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
|
|
@@ -385,6 +388,7 @@ const BaseSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
385
388
|
notFoundContent,
|
|
386
389
|
open: mergedOpen,
|
|
387
390
|
triggerOpen: mergedOpen,
|
|
391
|
+
rawOpen,
|
|
388
392
|
id,
|
|
389
393
|
showSearch,
|
|
390
394
|
multiple,
|
|
@@ -393,7 +397,7 @@ const BaseSelect = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
393
397
|
styles,
|
|
394
398
|
classNames,
|
|
395
399
|
lockOptions
|
|
396
|
-
}), [props, notFoundContent, triggerOpen, id, showSearch, multiple, mergedOpen, showScrollBar, styles, classNames, lockOptions]);
|
|
400
|
+
}), [props, notFoundContent, triggerOpen, id, showSearch, multiple, mergedOpen, rawOpen, showScrollBar, styles, classNames, lockOptions]);
|
|
397
401
|
|
|
398
402
|
// ==================================================================
|
|
399
403
|
// == Render ==
|
|
@@ -39,6 +39,7 @@ var _default = exports.default = /*#__PURE__*/React.forwardRef(function Multiple
|
|
|
39
39
|
disabled,
|
|
40
40
|
showSearch,
|
|
41
41
|
triggerOpen,
|
|
42
|
+
rawOpen,
|
|
42
43
|
toggleOpen,
|
|
43
44
|
autoClearSearchValue,
|
|
44
45
|
tagRender: tagRenderFromContext,
|
|
@@ -52,8 +53,9 @@ var _default = exports.default = /*#__PURE__*/React.forwardRef(function Multiple
|
|
|
52
53
|
|
|
53
54
|
// ===================== Search ======================
|
|
54
55
|
// Apply autoClearSearchValue logic: when dropdown is closed and autoClearSearchValue is not false (default true), clear search value
|
|
56
|
+
// Use rawOpen to avoid clearing search when emptyListContent blocks open
|
|
55
57
|
let computedSearchValue = searchValue;
|
|
56
|
-
if (!
|
|
58
|
+
if (!rawOpen && mode === 'multiple' && autoClearSearchValue !== false) {
|
|
57
59
|
computedSearchValue = '';
|
|
58
60
|
}
|
|
59
61
|
const inputValue = showSearch ? computedSearchValue || '' : '';
|
|
@@ -6,6 +6,7 @@ import * as React from 'react';
|
|
|
6
6
|
import type { BaseSelectProps } from '../BaseSelect';
|
|
7
7
|
export interface BaseSelectContextProps extends BaseSelectProps {
|
|
8
8
|
triggerOpen: boolean;
|
|
9
|
+
rawOpen: boolean;
|
|
9
10
|
multiple: boolean;
|
|
10
11
|
toggleOpen: (open?: boolean) => void;
|
|
11
12
|
lockOptions: boolean;
|
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