Skip to content

Commit

Permalink
fix(Autocomplete, ComboBox): disable browser autofill (#3419)
Browse files Browse the repository at this point in the history
  • Loading branch information
sashachabin committed May 8, 2024
1 parent c47c213 commit f805126
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
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

0 comments on commit f805126

Please sign in to comment.