Skip to content

Commit 508d095

Browse files
committed
fix: Should not clear input when showSearch is false
fix ant-design/ant-design#20421
1 parent 12e3a75 commit 508d095

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

examples/single.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Test extends React.Component {
6565
id="my-select"
6666
value={value}
6767
placeholder="placeholder"
68-
showSearch
68+
showSearch={false}
6969
style={{ width: 500 }}
7070
onBlur={this.onBlur}
7171
onFocus={this.onFocus}

src/Selector/Input.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,21 @@ interface InputProps {
1414
open: boolean;
1515
tabIndex: number;
1616

17-
onKeyDown: React.KeyboardEventHandler<HTMLInputElement | HTMLTextAreaElement | HTMLElement>;
18-
onMouseDown: React.MouseEventHandler<HTMLInputElement | HTMLTextAreaElement | HTMLElement>;
19-
onChange: React.ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement | HTMLElement>;
17+
onKeyDown: React.KeyboardEventHandler<
18+
HTMLInputElement | HTMLTextAreaElement | HTMLElement
19+
>;
20+
onMouseDown: React.MouseEventHandler<
21+
HTMLInputElement | HTMLTextAreaElement | HTMLElement
22+
>;
23+
onChange: React.ChangeEventHandler<
24+
HTMLInputElement | HTMLTextAreaElement | HTMLElement
25+
>;
2026
}
2127

22-
function fillRef(node: InputRef, ref: React.LegacyRef<InputRef> | React.Ref<InputRef>) {
28+
function fillRef(
29+
node: InputRef,
30+
ref: React.LegacyRef<InputRef> | React.Ref<InputRef>,
31+
) {
2332
if (typeof ref === 'function') {
2433
ref(node);
2534
} else if (ref && typeof ref === 'object') {
@@ -79,6 +88,7 @@ const Input: React.RefForwardingComponent<InputRef, InputProps> = (
7988
'aria-controls': `${id}_list`,
8089
'aria-activedescendant': `${id}_list_${accessibilityIndex}`,
8190
value: editable ? value : '',
91+
readOnly: !editable,
8292
onKeyDown: (event: React.KeyboardEvent<HTMLElement>) => {
8393
onKeyDown(event);
8494
if (onOriginKeyDown) {

tests/__snapshots__/Multiple.test.tsx.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ exports[`Select.Multiple render not display maxTagPlaceholder if maxTagCount not
2020
autocomplete="off"
2121
class="rc-select-selection-search-input"
2222
id="rc_select_TEST_OR_SSR"
23+
readonly=""
2324
role="combobox"
2425
style="opacity: 0;"
2526
value=""
@@ -111,6 +112,7 @@ exports[`Select.Multiple render truncates tags by maxTagCount and show maxTagPla
111112
autocomplete="off"
112113
class="rc-select-selection-search-input"
113114
id="rc_select_TEST_OR_SSR"
115+
readonly=""
114116
role="combobox"
115117
style="opacity: 0;"
116118
value=""
@@ -199,6 +201,7 @@ exports[`Select.Multiple render truncates tags by maxTagCount and show maxTagPla
199201
autocomplete="off"
200202
class="rc-select-selection-search-input"
201203
id="rc_select_TEST_OR_SSR"
204+
readonly=""
202205
role="combobox"
203206
style="opacity: 0;"
204207
value=""
@@ -276,6 +279,7 @@ exports[`Select.Multiple render truncates values by maxTagTextLength 1`] = `
276279
autocomplete="off"
277280
class="rc-select-selection-search-input"
278281
id="rc_select_TEST_OR_SSR"
282+
readonly=""
279283
role="combobox"
280284
style="opacity: 0;"
281285
value=""

tests/__snapshots__/Select.test.tsx.snap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ exports[`Select.Basic does not filter when filterOption value is false 1`] = `
1919
aria-owns="undefined_list"
2020
autocomplete="off"
2121
class="rc-select-selection-search-input"
22+
readonly=""
2223
role="combobox"
2324
style="opacity:0"
2425
value=""
@@ -191,6 +192,7 @@ exports[`Select.Basic no search 1`] = `
191192
aria-owns="undefined_list"
192193
autocomplete="off"
193194
class="rc-select-selection-search-input"
195+
readonly=""
194196
role="combobox"
195197
style="opacity:0"
196198
value=""
@@ -235,6 +237,7 @@ exports[`Select.Basic render renders aria-attributes correctly 1`] = `
235237
aria-owns="undefined_list"
236238
autocomplete="off"
237239
class="antd-selection-search-input"
240+
readonly=""
238241
role="combobox"
239242
style="opacity:0"
240243
value=""
@@ -289,6 +292,7 @@ exports[`Select.Basic render renders correctly 1`] = `
289292
aria-owns="undefined_list"
290293
autocomplete="off"
291294
class="antd-selection-search-input"
295+
readonly=""
292296
role="combobox"
293297
style="opacity:0"
294298
value=""
@@ -345,6 +349,7 @@ exports[`Select.Basic render renders data-attributes correctly 1`] = `
345349
aria-owns="undefined_list"
346350
autocomplete="off"
347351
class="antd-selection-search-input"
352+
readonly=""
348353
role="combobox"
349354
style="opacity:0"
350355
value=""
@@ -400,6 +405,7 @@ exports[`Select.Basic render renders disabled select correctly 1`] = `
400405
autocomplete="off"
401406
class="antd-selection-search-input"
402407
disabled=""
408+
readonly=""
403409
role="combobox"
404410
style="opacity:0"
405411
value=""
@@ -617,6 +623,7 @@ exports[`Select.Basic render renders role prop correctly 1`] = `
617623
aria-owns="undefined_list"
618624
autocomplete="off"
619625
class="antd-selection-search-input"
626+
readonly=""
620627
role="combobox"
621628
style="opacity:0"
622629
value=""
@@ -672,6 +679,7 @@ exports[`Select.Basic should contain falsy children 1`] = `
672679
aria-owns="undefined_list"
673680
autocomplete="off"
674681
class="rc-select-selection-search-input"
682+
readonly=""
675683
role="combobox"
676684
style="opacity:0"
677685
value=""
@@ -799,6 +807,7 @@ exports[`Select.Basic should render custom dropdown correctly 1`] = `
799807
autocomplete="off"
800808
class="rc-select-selection-search-input"
801809
id="rc_select_TEST_OR_SSR"
810+
readonly=""
802811
role="combobox"
803812
style="opacity: 0;"
804813
value=""

0 commit comments

Comments
 (0)