Skip to content

Commit 1169cb8

Browse files
authored
fix: render select input as text combobox (#1222)
1 parent 4e4700c commit 1169cb8

7 files changed

Lines changed: 24 additions & 19 deletions

File tree

src/SelectInput/Input.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>((props, ref) => {
161161
// Extract shared input props
162162
const sharedInputProps = {
163163
id,
164-
type: mode === 'combobox' ? 'text' : 'search',
164+
type: 'text',
165165
...restProps,
166166
ref: inputRef as React.Ref<HTMLInputElement>,
167167
style: {
@@ -170,7 +170,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>((props, ref) => {
170170
'--select-input-width': widthCssVar,
171171
} as React.CSSProperties,
172172
autoFocus,
173-
autoComplete: autoComplete || 'off',
173+
autoComplete: autoComplete || 'new-password',
174174
className: inputCls,
175175
disabled,
176176
value: value || '',

tests/Accessibility.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ describe('Select.Accessibility', () => {
285285

286286
const input = container.querySelector('input');
287287
expect(input).toHaveAttribute('role', 'combobox');
288+
// https://github.com/ant-design/ant-design/issues/57904
289+
expect(input).toHaveAttribute('type', 'text');
290+
expect(input).not.toHaveAttribute('list');
288291
expect(input).toHaveAttribute('aria-expanded', 'false');
289292
expect(input).toHaveAttribute('aria-haspopup', 'listbox');
290293
expect(input).not.toHaveAttribute('aria-owns');

tests/Select.test.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,14 +1424,16 @@ describe('Select.Basic', () => {
14241424
expect(container.querySelector('.rc-select-item-empty').textContent).toEqual('Not Found');
14251425
});
14261426

1427-
it('search input type', () => {
1427+
it('uses text input type and disables browser autocomplete for search', () => {
14281428
const { container } = render(
14291429
<Select showSearch open>
14301430
<Option value="1">1</Option>
14311431
<Option value="2">2</Option>
14321432
</Select>,
14331433
);
1434-
expect(container.querySelector('input').getAttribute('type')).toBe('search');
1434+
const input = container.querySelector('input');
1435+
expect(input.getAttribute('type')).toBe('text');
1436+
expect(input.getAttribute('autocomplete')).toBe('new-password');
14351437
});
14361438

14371439
it('warns on invalid children', () => {

tests/__snapshots__/Combobox.test.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ exports[`Select.Combobox renders controlled correctly 1`] = `
1717
aria-autocomplete="list"
1818
aria-expanded="false"
1919
aria-haspopup="listbox"
20-
autocomplete="off"
20+
autocomplete="new-password"
2121
class="rc-select-input"
2222
id="test-id"
2323
role="combobox"
@@ -45,7 +45,7 @@ exports[`Select.Combobox renders correctly 1`] = `
4545
aria-autocomplete="list"
4646
aria-expanded="false"
4747
aria-haspopup="listbox"
48-
autocomplete="off"
48+
autocomplete="new-password"
4949
class="rc-select-input"
5050
id="test-id"
5151
role="combobox"

tests/__snapshots__/Select.test.tsx.snap

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ exports[`Select.Basic render renders aria-attributes correctly 1`] = `
123123
aria-haspopup="listbox"
124124
aria-label="some-label"
125125
aria-labelledby="test-id"
126-
autocomplete="off"
126+
autocomplete="new-password"
127127
class="antd-input"
128128
id="test-id"
129129
role="combobox"
130-
type="search"
130+
type="text"
131131
value=""
132132
/>
133133
</div>
@@ -152,11 +152,11 @@ exports[`Select.Basic render renders correctly 1`] = `
152152
aria-autocomplete="list"
153153
aria-expanded="false"
154154
aria-haspopup="listbox"
155-
autocomplete="off"
155+
autocomplete="new-password"
156156
class="antd-input"
157157
id="test-id"
158158
role="combobox"
159-
type="search"
159+
type="text"
160160
value=""
161161
/>
162162
</div>
@@ -183,11 +183,11 @@ exports[`Select.Basic render renders data-attributes correctly 1`] = `
183183
aria-autocomplete="list"
184184
aria-expanded="false"
185185
aria-haspopup="listbox"
186-
autocomplete="off"
186+
autocomplete="new-password"
187187
class="antd-input"
188188
id="test-id"
189189
role="combobox"
190-
type="search"
190+
type="text"
191191
value=""
192192
/>
193193
</div>
@@ -212,12 +212,12 @@ exports[`Select.Basic render renders disabled select correctly 1`] = `
212212
aria-autocomplete="list"
213213
aria-expanded="false"
214214
aria-haspopup="listbox"
215-
autocomplete="off"
215+
autocomplete="new-password"
216216
class="antd-input"
217217
disabled=""
218218
id="test-id"
219219
role="combobox"
220-
type="search"
220+
type="text"
221221
value=""
222222
/>
223223
</div>
@@ -239,11 +239,11 @@ exports[`Select.Basic render renders role prop correctly 1`] = `
239239
aria-autocomplete="list"
240240
aria-expanded="false"
241241
aria-haspopup="listbox"
242-
autocomplete="off"
242+
autocomplete="new-password"
243243
class="antd-input"
244244
id="test-id"
245245
role="button"
246-
type="search"
246+
type="text"
247247
value=""
248248
/>
249249
</div>

tests/__snapshots__/Tags.test.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ exports[`Select.Tags OptGroup renders correctly 1`] = `
6565
aria-expanded="true"
6666
aria-haspopup="listbox"
6767
aria-owns="test-id_list"
68-
autocomplete="off"
68+
autocomplete="new-password"
6969
class="rc-select-input"
7070
id="test-id"
7171
role="combobox"
7272
style="--select-input-width: 0;"
73-
type="search"
73+
type="text"
7474
value=""
7575
/>
7676
</div>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Select.SSR should work 1`] = `"<div class="rc-select rc-select-single"><div class="rc-select-content"><div class="rc-select-placeholder" style="visibility:visible"></div><input id="test-id" type="search" readonly="" autoComplete="off" class="rc-select-input" role="combobox" aria-expanded="false" aria-haspopup="listbox" aria-autocomplete="list" value=""/></div></div>"`;
3+
exports[`Select.SSR should work 1`] = `"<div class="rc-select rc-select-single"><div class="rc-select-content"><div class="rc-select-placeholder" style="visibility:visible"></div><input id="test-id" type="text" readonly="" autoComplete="new-password" class="rc-select-input" role="combobox" aria-expanded="false" aria-haspopup="listbox" aria-autocomplete="list" value=""/></div></div>"`;

0 commit comments

Comments
 (0)