Skip to content

Commit 4649241

Browse files
committed
test: all of multiple
1 parent b606279 commit 4649241

3 files changed

Lines changed: 28 additions & 98 deletions

File tree

src/SelectInput/Content/MultipleContent.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ export default React.forwardRef<HTMLInputElement, SharedContentProps>(function M
3030
prefixCls,
3131
displayValues,
3232
searchValue,
33+
mode,
3334
onSelectorRemove,
3435
removeIcon: removeIconFromContext,
35-
36-
focused,
3736
} = useSelectInputContext();
3837
const {
3938
disabled,
4039
showSearch,
4140
triggerOpen,
4241
toggleOpen,
42+
autoClearSearchValue,
4343
tagRender: tagRenderFromContext,
4444
maxTagPlaceholder: maxTagPlaceholderFromContext,
4545
maxTagTextLength,
@@ -49,7 +49,13 @@ export default React.forwardRef<HTMLInputElement, SharedContentProps>(function M
4949
const selectionItemPrefixCls = `${prefixCls}-selection-item`;
5050

5151
// ===================== Search ======================
52-
const inputValue = showSearch ? searchValue : '';
52+
// Apply autoClearSearchValue logic: when dropdown is closed and autoClearSearchValue is not false (default true), clear search value
53+
let computedSearchValue = searchValue;
54+
if (!triggerOpen && mode === 'multiple' && autoClearSearchValue !== false) {
55+
computedSearchValue = '';
56+
}
57+
58+
const inputValue = showSearch ? computedSearchValue || '' : '';
5359
const inputEditable: boolean = showSearch && !disabled;
5460

5561
// Props from context with safe defaults

src/SelectInput/index.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface SelectInputProps extends Omit<React.HTMLAttributes<HTMLDivEleme
2121
searchValue?: string;
2222
activeValue?: string;
2323
mode?: Mode;
24+
autoClearSearchValue?: boolean;
2425
onSearch?: (searchText: string, fromTyping: boolean, isCompositing: boolean) => void;
2526
onSearchSubmit?: (searchText: string) => void;
2627
onInputBlur?: () => void;
@@ -104,8 +105,16 @@ export default React.forwardRef<SelectInputRef, SelectInputProps>(function Selec
104105
...restProps
105106
} = props;
106107

107-
const { triggerOpen, toggleOpen, showSearch, disabled, loading, classNames, styles } =
108-
useBaseProps();
108+
const {
109+
triggerOpen,
110+
toggleOpen,
111+
showSearch,
112+
disabled,
113+
loading,
114+
classNames,
115+
styles,
116+
autoClearSearchValue,
117+
} = useBaseProps();
109118

110119
const rootRef = React.useRef<HTMLDivElement>(null);
111120
const inputRef = React.useRef<HTMLInputElement>(null);
@@ -171,6 +180,14 @@ export default React.forwardRef<SelectInputRef, SelectInputProps>(function Selec
171180

172181
if (!(event.nativeEvent as any)._select_lazy) {
173182
inputRef.current?.focus();
183+
184+
// Clear search value if autoClearSearchValue is not false when closing
185+
if ((mode !== 'combobox' && (!showSearch || shouldPreventClose)) || !triggerOpen) {
186+
if (triggerOpen && autoClearSearchValue !== false) {
187+
onSearch?.('', true, false);
188+
}
189+
}
190+
174191
// Only toggle open if we should not prevent close
175192
if (!shouldPreventClose) {
176193
toggleOpen();

tests/__snapshots__/Multiple.test.tsx.snap

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,5 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Select.Multiple max tag render truncates tags by maxTagCount and show maxTagPlaceholder function 1`] = `
4-
<div
5-
class="rc-select rc-select-multiple rc-select-show-search"
6-
>
7-
<div
8-
class="rc-select-content"
9-
>
10-
<div
11-
class="rc-select-content-item"
12-
style="opacity: 1;"
13-
>
14-
<span
15-
class="rc-select-selection-item"
16-
title="One"
17-
>
18-
<span
19-
class="rc-select-selection-item-content"
20-
>
21-
One
22-
</span>
23-
<span
24-
aria-hidden="true"
25-
class="rc-select-selection-item-remove"
26-
style="user-select: none;"
27-
unselectable="on"
28-
>
29-
×
30-
</span>
31-
</span>
32-
</div>
33-
<div
34-
class="rc-select-content-item"
35-
style="opacity: 1;"
36-
>
37-
<span
38-
class="rc-select-selection-item"
39-
title="Two"
40-
>
41-
<span
42-
class="rc-select-selection-item-content"
43-
>
44-
Two
45-
</span>
46-
<span
47-
aria-hidden="true"
48-
class="rc-select-selection-item-remove"
49-
style="user-select: none;"
50-
unselectable="on"
51-
>
52-
×
53-
</span>
54-
</span>
55-
</div>
56-
<div
57-
class="rc-select-content-item rc-select-content-item-rest"
58-
style="opacity: 1;"
59-
>
60-
<span
61-
class="rc-select-selection-item"
62-
>
63-
<span
64-
class="rc-select-selection-item-content"
65-
>
66-
<span>
67-
1
68-
values omitted
69-
</span>
70-
</span>
71-
</span>
72-
</div>
73-
<div
74-
class="rc-select-content-item rc-select-content-item-suffix"
75-
style="opacity: 1;"
76-
>
77-
<input
78-
aria-autocomplete="list"
79-
aria-controls="test-id_list"
80-
aria-expanded="false"
81-
aria-haspopup="listbox"
82-
aria-owns="test-id_list"
83-
autocomplete="off"
84-
class="rc-select-input"
85-
id="test-id"
86-
role="combobox"
87-
style="--select-input-width: 0;"
88-
type="search"
89-
value=""
90-
/>
91-
</div>
92-
</div>
93-
</div>
94-
`;
95-
963
exports[`Select.Multiple max tag render truncates values by maxTagTextLength 1`] = `
974
[
985
"On...",

0 commit comments

Comments
 (0)