-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Autocomplete] Triggers change event twice with "enter" #18344
Comments
i think this problem of getOptionLabel
if enter:
### But work and no error if use
or
|
This comment has been minimized.
This comment has been minimized.
@setyawanandik Thank you for the feedback. Your codesandbox is invalid, see the error it reports. When you set <Autocomplete
freeSolo
options={[{ title: 'foo' }]}
- getOptionLabel={option => option.title}
+ getOptionLabel={option => typeof option === 'string' ? option : option.title} However, there is an interesting wrong behavior I haven't anticipated that surface here. The Enter key shouldn't trigger a new onChange event if its already currently selected. This can be solved with: diff --git a/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js b/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js
index ba7dcb7e4..2723e2648 100644
--- a/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js
+++ b/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js
@@ -531,7 +531,7 @@ export default function useAutocomplete(props) {
// We don't want to validate the form.
event.preventDefault();
selectNewValue(event, filteredOptions[highlightedIndexRef.current]);
- } else if (freeSolo && inputValue !== '') {
+ } else if (freeSolo && inputValueFilter !== '') {
selectNewValue(event, inputValue);
}
break; Do you want to work on this problem? We would need to add a test case as it's subtle. |
@oliviertassinari - I experienced the same issue, but am not using freeSolo. I used your getOptionLabel workaround I used the combo box example straight off the site with my dataset which is just an array of
|
I encounter the same issue with |
I can try and work on a test case for this @oliviertassinari if no one else has started on one. |
@tplai Awesome, you are free to go :) |
@gmltA This should already be possible by controlling the value prop. |
Current Behavior 😯
I have used Autocomplete with FreeSolo prop, but I have a problem. when I have typed the word in the textfield / input and then I press Enter, the textfield becomes blank (deleted text). What I want, the word doesn't disappear when I press enter, how do I fix this?
https://codesandbox.io/s/material-demo-k1uyh
Expected Behavior 🤔
If I type text in the textfield and then I press Enter, the text should not be lost or not deleted
Your Environment 🌎
The text was updated successfully, but these errors were encountered: