-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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] Add an option to not resetInputValue on selectNewValue #36085
Comments
The "reset" event is triggered in the following cases:
Instead of adding yet another prop to control the behavior, I'm more inclined to expose a state reducer that will allow a much greater degree of control over the internals of the autocomplete. This, however, is a significant change. We're planning to overhaul the useAutocomplete logic, so I'll try to include this in this effort. I can't commit to any timeframes, though. |
Would it be a good idea to first add a new prop (I think, |
From what I understand: Problem
How to solve thisAt a high level, we need to give more granularity to the events to disambiguate. Options
diff --git a/packages/mui-base/src/useAutocomplete/useAutocomplete.js b/packages/mui-base/src/useAutocomplete/useAutocomplete.js
index 8af5d5cbec..4dd54ba584 100644
--- a/packages/mui-base/src/useAutocomplete/useAutocomplete.js
+++ b/packages/mui-base/src/useAutocomplete/useAutocomplete.js
@@ -682,7 +682,7 @@ export default function useAutocomplete(props) {
}
}
- resetInputValue(event, newValue);
+ resetInputValue(event, newValue, reasonProp);
handleValue(event, newValue, reason, { option });
if (!disableCloseOnSelect && (!event || (!event.ctrlKey && !event.metaKey))) {
I think that 1. could be good enough, and aligned with the current API. It's probably a breaking change though, as what used to be "1 reason" would turn into "X reasons" based on the case. |
hi @oliviertassinari can you help me review this PR? |
Is it possible to differentiate between these 2 cases in
I have a use case where I don't want to update input value only when the value prop changes but not in case when a new value is selected. (In case of multiple selections). |
Duplicates
Latest version
Summary 💡
Currently, the autocomplete behaves like this:
I believe this is because of this line
material-ui/packages/mui-base/src/AutocompleteUnstyled/useAutocomplete.js
Line 678 in 684cd85
I was hoping for an option for me to edit that line such as
if (clearOnSelect) resetInputValue(event, newValue);
Examples 🌈
I was able to make a workaround like this, but I think this can be dangerous because I'm not sure what can trigger the "reset" event.
https://codesandbox.io/s/long-monad-8l0nrm?file=/demo.tsx
Motivation 🔦
Our designers asked if we can do this and I do think this can be helpful.
The text was updated successfully, but these errors were encountered: