I have the code below
<Autocomplete
id='combo-box-demo'
options={companies}
getOptionLabel={getOptionLabel}
renderInput={params => (
<TextField {...params} variant='outlined' />
)}
onChange={(event, newValue) => onCompanyChange(event, newValue)}
/>
I want to customized the function when I clicked on the clear button in the autocomplete input. I need to ask the user if they really wants to clear the field first. Is it possible to target the .MuiAutocomplete-clearIndicator so I can add more function on it? Thank is advance!
const onCompanyChange = (event, value, reason) => {
if(reason === "clear")
confirm("Are you sure to clear?"); // or you can open Dialog here
//other codes go here like setting the value of input
};
<Autocomplete
id='combo-box-demo'
options={companies}
getOptionLabel={getOptionLabel}
renderInput={params => (
<TextField {...params} variant='outlined' />
)}
onChange={onCompanyChange}
/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With