I have a problem with Autocomplete component. He works well, until I need to clear my selection (i.e. I changed my mind and want to unselect and leave empty field) before submitting form and make state empty. In documentation examples works fine with this task, but in my code it doesn't work.
Here my code:
<Autocomplete
classes={{
root: classes.root
}}
style={{padding: 0}}
options={positionArr}
getOptionLabel={(option) => option.name}
renderInput={(params) => (
<TextField
{...params}
className={`inputPadding`}
classes={{root: classes.labelRoot}}
label={t('position')}
variant="outlined"
helperText={t('optional')}
/>
)}
getOptionSelected={(opt, val) => opt === val}
value={positionObjTwo}
onChange={(e, val) => {val && setPositionObjTwo(val)}}
/>
positionArr looks like:
[
{
id: 1,
name: 'AB'
},
{
id: 2,
name: 'AB/2OFF'
},
...
]