Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/SelectInput/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>((props, ref) => {
// Extract shared input props
const sharedInputProps = {
id,
type: mode === 'combobox' ? 'text' : 'search',
type: 'text',
...restProps,
ref: inputRef as React.Ref<HTMLInputElement>,
style: {
Expand All @@ -171,7 +171,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>((props, ref) => {
'--select-input-width': widthCssVar,
} as React.CSSProperties,
autoFocus,
autoComplete: autoComplete || 'off',
autoComplete: autoComplete || 'new-password',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

避免用 || 覆盖显式空字符串的 autoComplete

Line 174 建议改为 ??。当前写法会把调用方传入的 "" 覆盖为 'new-password',行为不够精确。

🔧 建议修改
-    autoComplete: autoComplete || 'new-password',
+    autoComplete: autoComplete ?? 'new-password',
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
autoComplete: autoComplete || 'new-password',
autoComplete: autoComplete ?? 'new-password',
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/SelectInput/Input.tsx` at line 174, The autoComplete fallback uses
logical OR which treats an explicit empty string as falsy; update the assignment
in Input.tsx (the autoComplete property where it currently reads autoComplete:
autoComplete || 'new-password') to use the nullish coalescing operator so that
only null or undefined trigger the default (i.e., replace the `||` fallback with
`??` for the autoComplete property in the SelectInput/Input component).

className: inputCls,
disabled,
value: value || '',
Expand Down
3 changes: 3 additions & 0 deletions tests/Accessibility.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ describe('Select.Accessibility', () => {

const input = container.querySelector('input');
expect(input).toHaveAttribute('role', 'combobox');
// https://github.com/ant-design/ant-design/issues/57904
expect(input).toHaveAttribute('type', 'text');
expect(input).not.toHaveAttribute('list');
expect(input).toHaveAttribute('aria-expanded', 'false');
expect(input).toHaveAttribute('aria-haspopup', 'listbox');
expect(input).not.toHaveAttribute('aria-owns');
Expand Down
6 changes: 4 additions & 2 deletions tests/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1426,14 +1426,16 @@ describe('Select.Basic', () => {
expect(container.querySelector('.rc-select-item-empty').textContent).toEqual('Not Found');
});

it('search input type', () => {
it('uses text input type and disables browser autocomplete for search', () => {
const { container } = render(
<Select showSearch open>
<Option value="1">1</Option>
<Option value="2">2</Option>
</Select>,
);
expect(container.querySelector('input').getAttribute('type')).toBe('search');
const input = container.querySelector('input');
expect(input.getAttribute('type')).toBe('text');
expect(input.getAttribute('autocomplete')).toBe('new-password');
});

it('warns on invalid children', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/__snapshots__/Combobox.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exports[`Select.Combobox renders controlled correctly 1`] = `
aria-autocomplete="list"
aria-expanded="false"
aria-haspopup="listbox"
autocomplete="off"
autocomplete="new-password"
class="rc-select-input"
id="test-id"
role="combobox"
Expand Down Expand Up @@ -45,7 +45,7 @@ exports[`Select.Combobox renders correctly 1`] = `
aria-autocomplete="list"
aria-expanded="false"
aria-haspopup="listbox"
autocomplete="off"
autocomplete="new-password"
class="rc-select-input"
id="test-id"
role="combobox"
Expand Down
20 changes: 10 additions & 10 deletions tests/__snapshots__/Select.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ exports[`Select.Basic render renders aria-attributes correctly 1`] = `
aria-haspopup="listbox"
aria-label="some-label"
aria-labelledby="test-id"
autocomplete="off"
autocomplete="new-password"
class="antd-input"
id="test-id"
role="combobox"
type="search"
type="text"
value=""
/>
</div>
Expand All @@ -152,11 +152,11 @@ exports[`Select.Basic render renders correctly 1`] = `
aria-autocomplete="list"
aria-expanded="false"
aria-haspopup="listbox"
autocomplete="off"
autocomplete="new-password"
class="antd-input"
id="test-id"
role="combobox"
type="search"
type="text"
value=""
/>
</div>
Expand All @@ -183,11 +183,11 @@ exports[`Select.Basic render renders data-attributes correctly 1`] = `
aria-autocomplete="list"
aria-expanded="false"
aria-haspopup="listbox"
autocomplete="off"
autocomplete="new-password"
class="antd-input"
id="test-id"
role="combobox"
type="search"
type="text"
value=""
/>
</div>
Expand All @@ -212,12 +212,12 @@ exports[`Select.Basic render renders disabled select correctly 1`] = `
aria-autocomplete="list"
aria-expanded="false"
aria-haspopup="listbox"
autocomplete="off"
autocomplete="new-password"
class="antd-input"
disabled=""
id="test-id"
role="combobox"
type="search"
type="text"
value=""
/>
</div>
Expand All @@ -239,11 +239,11 @@ exports[`Select.Basic render renders role prop correctly 1`] = `
aria-autocomplete="list"
aria-expanded="false"
aria-haspopup="listbox"
autocomplete="off"
autocomplete="new-password"
class="antd-input"
id="test-id"
role="button"
type="search"
type="text"
value=""
/>
</div>
Expand Down
4 changes: 2 additions & 2 deletions tests/__snapshots__/Tags.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ exports[`Select.Tags OptGroup renders correctly 1`] = `
aria-expanded="true"
aria-haspopup="listbox"
aria-owns="test-id_list"
autocomplete="off"
autocomplete="new-password"
class="rc-select-input"
id="test-id"
role="combobox"
style="--select-input-width: 0;"
type="search"
type="text"
value=""
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/__snapshots__/ssr.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

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>"`;
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>"`;
Loading