I am trying to set up Material UI's Autocomplete component so that when you hit tab it will automatically select the closest match. Based on the input I then need to capture the e.target.value. However, it only seems to pass the string that is manually entered without the autocompleted string. For example, if I type "Ba" and tab to complete to "Banana" only "Ba" is passed as the value. Here is a sandbox of what I am trying to implement.
I also realise that when I click to use the dropdown menu (instead of manually entering values via keyboard) it fails to even create the value I am after. Any help on this is also very much appreciated. Thank you!
1 Answer 1
You may either create an object that fit handleChange's signature with the valueparameter of the onChange function, i.e.
<Autocomplete
onChange={(event, value) => {
handleChange({
target: {
name: event.target.name,
value,
},
});
}}
...
or update the handleChange function.
Comments
Explore related questions
See similar questions with these tags.
valueandinputValueare set to "Banana"? I am using Google Chrome.e.target.valueinstead of thevalueparameter in theonChangefunction?eas one of the arguments.e.target.nameande.target.valueare then used to update state in another component.valueparameter is the value you want, my suggestion is to either create an object that fithandleChange's signature with thevalueparameter, e.g.{ target: { name: e.target.name, value: newValue } }or update thehandleChangefunction. Hope you can find a solution eventually or others can help!