-
Notifications
You must be signed in to change notification settings - Fork 42
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
Fix issues with controlled Select #1471
base: development
Are you sure you want to change the base?
Fix issues with controlled Select #1471
Conversation
d1351c3
to
bb4d346
Compare
bb4d346
to
c6aa9b2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work, Niko! This helps us a lot. Thanks for your contribution. Now we have a state that doesn't mix up. Yep, the main problem was onChange
in the state.
I rebased this on the latest development
, fixed the conflict and updated reference images (as the clearable
property is now false
as a default)
c6aa9b2
to
ce24330
Compare
If onChange is in state, it keeps ref to the initial "optionGroups". Easily tested by selecting an option, changing language and selecting again. Lang is always the initial (fi)
Does not fix anything, but is a good practice.
onKeyDown is memoized, but the dependency array is empty, so the ref to the function does not update
The trigger function was not compared, so clicking an item second time, used old data in the memoized trigger.
When parent of the DataProvider is re-rendered and new data is passed, the old is cleared. onReset can restore data from the state the storages were before reset.
If props change, the "open" is reset to the value it was before re-render. Usually it was "false", so the menu will close once props change. This is not good behaviour when multiselect items are selected and list keeps closing. The "open" value is restored on each render.
… options are externally updated If groups are reset externally, the group label is not updated accordingly.
ce24330
to
56a466e
Compare
Description
Fixed following issues:
multiselect memoization issue: when selecting an option calls the
onChange
which then refreshes props and re-renders the component, the selected option keeps has old data in the memoized "trigger" function. When an option with old "trigger" reference is unselected, the whole data set is reverted to old state and selections made after it are cleared.crash if keyboard is used after
onChange
re-renders the component. Memoization issue in theuseKeyboard
.onKeyDown
did not have correct dependencies."open" state was not kept consistently when
onChange
caused re-render. When component props change, theopen
can be reverted to closed-state even if the component has internally opened it. This causes the multiselect close on each selection. The reset of the internal state is now handled by comparing old state with new props after a re-render.Multiselect groups with all options selected are not marked selected after re-render and clicking them had no effect.