Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material-UI Autocomplete & TextField triggers google autocomplete

I am trying to implement the Autocomplete component into my project but am getting the autofill/autocomplete from the browser after some time. Do you know how I can set it to off ?

                        <Autocomplete

                            id="combo-box-demo"
                            options={battleRepos}
                            getOptionLabel={option => option.full_name}
                            style={{ width: 500 }}
                            renderInput={params => (
                                <TextField {...params} 
                                    label="Combo box"  
                                    variant="outlined"
                                    onBlur={event => console.log(event.target.value)}

                                    fullWidth  />
                            )}
                        />

Image with the problem

like image 411
Gim-Cojocaru Raul-Cristian Avatar asked Nov 18 '19 14:11

Gim-Cojocaru Raul-Cristian


People also ask

How do you create an autocomplete reaction?

To create an autocomplete component in React, use the react-autocomplete library. The react-autocomplete module provides properties, methods, and events that can trigger an ajax request on typing, which will fetch the list items and render them inside the render menu.

How do you set autocomplete value?

The selected value of the AutoComplete can only be a string value. To set the value, use the [value] property binding of the component or the ngModel binding.

How do I turn off autocomplete in MUI?

To hide browser autocomplete with React Material UI Autocomplete and TextField, we can set inputProps. autocomplete to 'off' . We set inputProps. autoComplete to 'off' in the renderInput function to disable browser autocomplete in the text field.


2 Answers

UPDATE

With the release of @material-ui/core 4.7.0 and @material-ui/lab 4.0.0-alpha.33, this is now fixed and no longer requires the workaround shown below.


This has been fixed in a recent pull request, but is not yet released (will be in the next release).

If you want to work around this prior to it being released (which will likely be within a few days), you can set inputProps.autoComplete = "off" like in the following:

<Autocomplete
    id="combo-box-demo"
    options={battleRepos}
    getOptionLabel={option => option.full_name}
    style={{ width: 500 }}
    renderInput={params => {
        const inputProps = params.inputProps;
        inputProps.autoComplete = "off";
        return (
          <TextField
            {...params}
            inputProps={inputProps}
            label="Combo box"  
            variant="outlined"
            onBlur={event => console.log(event.target.value)}
            fullWidth
          />
        );
      }
    }
/>

like image 165
Ryan Cogswell Avatar answered Oct 01 '22 11:10

Ryan Cogswell


Even with the latest:

 "@material-ui/core" 
 "@material-ui/lab"

which contains the autoComplete property set to 'off', I wasn't able to get the autofill box go away.

Also tried setting the attribute on the form tag <form autoComplete="off">...</form>

To no avail.

The thing which resolved the issue was setting the autoComplete field to 'new-password'

<Autocomplete
    id='id'
    options={data}
    onChange={(e, val) => input.onChange(val)}
    renderInput={(params) => {
        params.inputProps.autoComplete = 'new-password';
        return <TextField {...params}
            label={label} placeholder="Type to Search" />
    }} 
/>
like image 36
Eugen Sunic Avatar answered Oct 01 '22 11:10

Eugen Sunic