Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Autocomplete, ComboBox): disable browser autofill #3419

Merged
merged 2 commits into from
May 8, 2024
Merged
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
2 changes: 2 additions & 0 deletions packages/react-ui/components/Autocomplete/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ export class Autocomplete extends React.Component<AutocompleteProps, Autocomplet
const inputProps = {
...rest,
width: '100%',
autoComplete: 'off',
onValueChange: this.handleValueChange,
onKeyDown: this.handleKeyDown,
onFocus: this.handleFocus,
Expand Down Expand Up @@ -307,6 +308,7 @@ export class Autocomplete extends React.Component<AutocompleteProps, Autocomplet

private renderMobileMenu = () => {
const inputProps: InputProps = {
autoComplete: 'off',
autoFocus: true,
width: '100%',
onValueChange: this.handleValueChange,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,12 @@ describe('<Autocomplete />', () => {
expect(menuItems).toHaveTextContent('1');
});

it('should disable default browser autofill', () => {
const props = { value: '', source: [], onValueChange: () => '' };
render(<Autocomplete {...props} />);
expect(screen.getByRole('textbox')).toHaveAttribute('autocomplete', 'off');
});

describe('a11y', () => {
it('should connect dropdown with input through aria-controls', async () => {
const Comp = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,12 @@ describe('ComboBox', () => {
expect(screen.getByTestId(InputLikeTextDataTids.nativeInput)).toBeDisabled();
});

it('should disable default browser autofill', () => {
render(<ComboBox getItems={() => Promise.resolve([])} />);
userEvent.click(screen.getByTestId(InputLikeTextDataTids.root));
expect(screen.getByRole('textbox')).toHaveAttribute('autocomplete', 'off');
});

describe('a11y', () => {
it('props aria-describedby applied correctly on Input', () => {
const getItems = () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/react-ui/internal/CustomComboBox/ComboBoxView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ export class ComboBoxView<T> extends React.Component<ComboBoxViewProps<T>> {
}

const inputProps: InputProps = {
autoComplete: 'off',
autoFocus: true,
width: '100%',
onFocus,
Expand Down Expand Up @@ -333,6 +334,7 @@ export class ComboBoxView<T> extends React.Component<ComboBoxViewProps<T>> {
ref={this.refInput}
warning={warning}
inputMode={inputMode}
autoComplete="off"
aria-describedby={ariaDescribedby}
aria-controls={this.menuId}
aria-label={ariaLabel}
Expand Down