Yogesh Saroya
Yogesh Saroya

Reputation: 1515

How to override autocomplete/autofill in material-ui autocomplete - React JS

I am using material-ui autocomplete ( https://mui.com/components/autocomplete/#free-solo ).

It's working fine, demo is here : https://codesandbox.io/s/0v9v9?file=/demo.tsx

by default Text input is showing autoComplete='off' but i want to change it to autoComplete='new-something' but it's not working and autoComplete='new-something' is showing as parent dev attribute instead of Input

I used this code

<TextField
  {...params}
  inputProps={{
    ...params.inputProps,
    autoComplete: 'new-something',
  }}
/>

But it's not working. In input it's still showing autocomplete="off" as input attribute.

Upvotes: 1

Views: 2606

Answers (1)

MoiioM
MoiioM

Reputation: 1974

As you can see in the doc https://mui.com/api/text-field/#props there is two props with the same name

  • inputProps: Attributes applied to the input element.
  • InputProps: Props applied to the Input element.

For autocomplete attribute you need inputProps

   <TextField
      {...params}
      label="Search input"
      InputProps={
        ...params.InputProps,
        type: 'search',
      }}
      inputProps={{
        autocomplete: 'something'
      }}
    />

Here a working exanple in the codesanbox https://codesandbox.io/s/freesolo-material-demo-forked-8g2n1?file=/demo.tsx

Upvotes: 1

Related Questions