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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Select also accepts public props from `BaseSelect`, except `showSearch`, which i

| Name | Description | Type | Default |
| --- | --- | --- | --- |
| autoComplete | Browser autocomplete hint for the search input. | string | `new-password` |
| autoClearSearchValue | Deprecated. Use `showSearch.autoClearSearchValue` instead. | boolean | true |
| backfill | Backfill the active option into the input. Only works in `combobox` mode. | boolean | false |
| children | Legacy option children. Prefer `options` for new code. | ReactNode | - |
Expand Down
1 change: 1 addition & 0 deletions src/BaseSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export interface BaseSelectProps
tagRender?: (props: CustomTagProps) => React.ReactElement;
direction?: 'ltr' | 'rtl';
autoFocus?: boolean;
autoComplete?: string;
placeholder?: React.ReactNode;
maxCount?: number;

Expand Down
3 changes: 2 additions & 1 deletion src/SelectInput/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>((props, ref) => {
autoFocus,
tokenWithEnter,
placeholder,
autoComplete: contextAutoComplete,
components: { input: InputComponent = 'input' },
} = useSelectInputContext();
const { id, classNames, styles, open, activeDescendantId, role, disabled } = useBaseProps() || {};
Expand Down Expand Up @@ -170,7 +171,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>((props, ref) => {
'--select-input-width': widthCssVar,
} as React.CSSProperties,
autoFocus,
autoComplete: autoComplete || 'new-password',
autoComplete: autoComplete ?? contextAutoComplete ?? 'new-password',
className: inputCls,
disabled,
value: value || '',
Expand Down
2 changes: 2 additions & 0 deletions src/SelectInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface SelectInputProps extends Omit<React.HTMLAttributes<HTMLDivEleme
onSelectorRemove?: (value: DisplayValueType) => void;
maxLength?: number;
autoFocus?: boolean;
autoComplete?: string;
/** Check if tokenization should treat pasted line breaks as separators */
tokenWithEnter?: boolean;
// Add other props that need to be passed through
Expand All @@ -60,6 +61,7 @@ const DEFAULT_OMIT_PROPS = [
'onPopupScroll',
'tabIndex',
'activeValue',
'autoComplete',
'onSelectorRemove',
'focused',
] as const;
Expand Down
13 changes: 12 additions & 1 deletion tests/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,7 @@ describe('Select.Basic', () => {
expect(container.querySelector('.rc-select-item-empty').textContent).toEqual('Not Found');
});

it('uses text input type and disables browser autocomplete for search', () => {
it('uses text input type with autocomplete suppression by default', () => {
const { container } = render(
<Select showSearch open>
<Option value="1">1</Option>
Expand All @@ -1436,6 +1436,17 @@ describe('Select.Basic', () => {
expect(input.getAttribute('autocomplete')).toBe('new-password');
});

it('forwards autocomplete to the search input', () => {
const { container } = render(
<Select showSearch open autoComplete="off">
<Option value="1">1</Option>
</Select>,
);

expect(container.querySelector('input')).toHaveAttribute('autocomplete', 'off');
expect(container.querySelector('.rc-select')).not.toHaveAttribute('autocomplete');
});

it('warns on invalid children', () => {
const Foo = (value) => <div>foo{value}</div>;
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => null);
Expand Down
Loading