1
 <Autocomplete
 disablePortal
 id="geo-select-country"
 options={all_country}
 defaultValue={nation}
 onChange={(event, selected_nation) => {
 set_nation(selected_nation);
 }}
 classes={autocomplete_classes}
 renderInput={(params) => (
 <TextField {...params} label={"Country"} margin="none" focused />
 )}
 />

For example, if I type out "United States" and then click enter or click away, nothing will be selected. I would have to click on the dropdown suggestion for "United States" in order for it to be selected.

Why do I fix this?

EDITED:

Here is a live example:

https://codesandbox.io/s/wizardly-frost-9cj0v?file=/src/App.js

Values can only be selected if you actually click them in the dropdown. Even if you type the value exactly as it is suggested and then click enter, it will not be selected.

asked Jan 5, 2022 at 3:07
6
  • 1
    how about using it with autoHighlight={true} prop ? Commented Jan 5, 2022 at 3:20
  • This worked if ENTER is pressed. But if I click outside of the AutoComplete after typing a valid value, it will be discarded. What is the fix for the later? Commented Jan 5, 2022 at 3:45
  • 1
    I think autoSelect={true} will solve later problem Commented Jan 5, 2022 at 3:47
  • both worked, thanks Commented Jan 5, 2022 at 3:48
  • You're welcome, Is it ok to post it as answer? Commented Jan 5, 2022 at 3:48

1 Answer 1

1

To solve selecting value by pressing Enter, you can use autoHighlight={true} prop and also in order to solve the clicking outside issue, you can use autoSelect={true} with Autocomplete.

answered Jan 5, 2022 at 3:51
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.