Autocomplete element stop working after adding 'InputProps' prop to the TextField.
I want to render Autocomplete with custom 'startAdornment'
const AppSelectAutocomplete = () => {
const classes = useStyles();
const [state, setState] = React.useState(null);
return (
<Autocomplete
// open
freeSolo
selectOnFocus
autoHighlight
value={state}
loading={false}
options={countries}
style={{ width: 500 }}
onChange={(e, option) => setState(option)}
className="AutocompleteLocation"
classes={{ option: classes.option }}
getOptionLabel={option => option.app_name}
renderOption={option => (
<div className="AutocompleteLocation-dropdown">
<span className="app-logo">
<img src={option.img} alt={option.app_name} />
</span>
<div className="AutocompleteLocation-text">
<span className="app-name">{option.app_name}</span>
<span className="app-publisher">{option.publisher}</span>
</div>
</div>
)}
renderInput={params => {
return (
<TextField
{...params}
placeholder="Aplication name"
variant="outlined"
InputProps={{ startAdornment: 's' }} // ??????? If enable this prop Autocomplete will stop working
inputProps={{
...params.inputProps,
autoComplete: 'new-password'
}}
/>
);
}}
/>
);
};
I want to render Autocomplete with custom 'startAdornment'
| Tech | Version |
| ----------- | ------- |
| Material-UI | v4.9.3 |
| React | v16.12.0 |
| Browser | Chrome |
I found out the reason. It's because I didn't pass ...params.InputProps to InputProps... 馃槗
It should be like this: InputProps={{ ...params.InputProps, startAdornment: <div/>}}
Most helpful comment
I found out the reason. It's because I didn't pass
...params.InputPropsto InputProps... 馃槗It should be like this:
InputProps={{ ...params.InputProps, startAdornment: <div/>}}