-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
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] Multiple + freeSolo crash #18110
Labels
bug 🐛
Something doesn't work
component: autocomplete
This is the name of the generic UI component, not the React module!
good first issue
Great for first contributions. Enable to learn the contribution process.
Comments
oliviertassinari
added
component: Autocomplete
bug 🐛
Something doesn't work
component: autocomplete
This is the name of the generic UI component, not the React module!
and removed
component: Autocomplete
labels
Oct 30, 2019
@ideoclickVanessa Thanks for the report! I assure you, it's not the only way to crash the component. In a week or two, it will be more reliable 💪. You can follow our progress with https://github.com/mui-org/material-ui/labels/component%3A%20Autocomplete. |
What do you think of this diff? diff --git a/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js b/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js
index bc02f10f1..7f28ddca2 100644
--- a/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js
+++ b/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js
@@ -163,14 +163,19 @@ export default function useAutocomplete(props) {
const [focused, setFocused] = React.useState(false);
const resetInputValue = useEventCallback(newValue => {
- setInputValue(newValue != null ? getOptionLabel(newValue) : '');
+ let newInputValue;
+ if (multiple) {
+ newInputValue = '';
+ } else {
+ newInputValue = newValue != null ? getOptionLabel(newValue) : '';
+ }
+
+ setInputValue(newInputValue);
});
React.useEffect(() => {
- if (!multiple) {
- resetInputValue(value);
- }
- }, [value, multiple, resetInputValue]);
+ resetInputValue(value);
+ }, [value, resetInputValue]);
const { current: isOpenControlled } = React.useRef(openProp != null);
const [openState, setOpenState] = React.useState(false);
@@ -375,11 +380,7 @@ export default function useAutocomplete(props) {
handleClose(event);
}
- if (multiple) {
- setInputValue('');
- } else {
- setInputValue(getOptionLabel(newValue));
- }
+ resetInputValue(newValue);
selectedIndexRef.current = -1;
};
@@ -550,7 +551,7 @@ export default function useAutocomplete(props) {
if (autoSelect && selectedIndexRef.current !== -1) {
handleValue(event, filteredOptions[selectedIndexRef.current]);
} else if (!freeSolo) {
- setInputValue((value && getOptionLabel(value)) || '');
+ resetInputValue(value);
}
handleClose(event); |
oliviertassinari
changed the title
[AutoComplete] <ForwardRef(Autocomplete)> Crash
[AutoComplete] Multiple + freeSolo crash
Oct 30, 2019
oliviertassinari
added
the
good first issue
Great for first contributions. Enable to learn the contribution process.
label
Oct 30, 2019
1 task
2 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bug 🐛
Something doesn't work
component: autocomplete
This is the name of the generic UI component, not the React module!
good first issue
Great for first contributions. Enable to learn the contribution process.
I was playing around with the Autocomplete component in codesandbox to see if it would be worth switching to from react-select. Unfortunately, I can very reliably trigger a page crash due to an error occurring in the <ForwardRef(Autocomplete)> component.
Current Behavior 😯
<ForwardRef(Autocomplete)> component throws an error almost all of the time.
Expected Behavior 🤔
The box's menu opens and closes without error
Steps to Reproduce 🕹
https://codesandbox.io/s/material-demo-hwcj7
Steps:
Context 🔦
Now that Material UI is building their own AutoComplete component, I would rather use it than react-select.
The text was updated successfully, but these errors were encountered: