Skip to content
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

Add selected item already in state reducer #2594

Merged
merged 1 commit into from
Jul 11, 2022

Conversation

Kadrian
Copy link
Collaborator

@Kadrian Kadrian commented Jul 11, 2022

Since onStateChange only gets called on state diff,
and selectedItem isn't cleared when an item is removed,
it won't "change", when it's removed and re-added again.
So we didn't get the change.

There also doesn't seem to be a way to clear selectedItem, except for
reset, which would also reset the menu (--> close it).

Solution: we don't use onStateChange anymore, but a side effect of
the stateReducer instead. Doesn't feel great, but seems to work.

The downshift docs are wrong, recommending to call addSelectedItem in
onStateChange, because all of their examples work with a closing menu,
after selecting one item.

We're keeping the menu open.

Since onStateChange only gets called on state diff,
and selectedItem isn't cleared when an item is removed,
it won't "change", when it's removed and re-added again.
So we didn't get the change.

There also doesn't seem to be a way to clear selectedItem, except for
reset, which would also reset the menu (--> close it).

Solution: we don't use onStateChange anymore, but a side effect of
the stateReducer instead. Doesn't feel great, but seems to work.

The downshift docs are wrong, recommending to call addSelectedItem in
onStateChange, because all of their examples work with a closing menu,
after selecting one item.

We're keeping the menu open.
@Kadrian Kadrian changed the title Add selected item already in state reducer, Add selected item already in state reducer Jul 11, 2022
@Kadrian Kadrian requested a review from awildturtok July 11, 2022 15:13
@Kadrian Kadrian merged commit 147d093 into develop Jul 11, 2022
@delete-merged-branch delete-merged-branch bot deleted the fix-select-remove-and-select-again branch July 11, 2022 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant