-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
[Select] Out of range defaultValue causes onChange to fire on mount #7
Comments
A warning here is a good idea, but I did the resetting to no selected value when an invalid one is provided on purpose. Of course, whether it leads to better or worse DX depends on the use case, so I'd wait for additional feedback before changing it. |
Yeah 🙌🏼 that works.
What confused me was that the value change that caused the This unexpected I think the root of this is that the initial state's |
Gotcha. Do you think a warning in the console would be sufficient to help debug these issues? I'm not strictly against not firing the BTW, it may turn out we need to support nonexistent values somehow to solve #37, but we haven't investigated possible implementations yet. |
It would be an improvement, but it would still be up to the developer to connect the "Warning nonexistent value" with the
I agree that if the value changes, then For the " For the " I wonder how this behavior would affect the case of async loading of options: for example, a Select with virtualization, if the user selects a value and then scrolls the listbox, making the selected option unmount, would we trigger |
Hello @michaldudak, I'd like to tackle this however what do you think is the best solution? Imo not triggering the onChange and showing a warning is fine for me - is there any additional things I need to do? |
The Select will soon undergo a severe API change, which may affect its internals. Let's not spend time on fixing its bugs till then (as it may be fixed during the API change). |
Duplicates
Latest version
Steps to reproduce 🕹
Link to live example: https://codesandbox.io/s/use-select-default-value-triggers-on-change-h5mmmh?file=/Demo.js
Steps:
Select
component using theuseSelect
hookonChange
callback touseSelect
defaultValue
touseSelect
which doesn't correspond to any of the options' valuesCurrent behavior 😯
When the component mounts, the
onChange
callback is fired withnull
values for theevent
andnewValue
parameters.Expected behavior 🤔
onChange
callback shouldn't fireuseSelect
being out of rangeContext 🔦
Refactoring
material-ui
v5 Select to be based on theuseSelect
hook. Hopefully, we can make it so that the refactored version fails gracefully whenvalue = ""
ordefaultValue = ""
as that was the way to deselect all options in v5.Your environment 🌎
npx @mui/envinfo
The text was updated successfully, but these errors were encountered: