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

fix(useMultipleSelect): removeSelectedItem adding duplicate items to selected items #1353

Merged
merged 2 commits into from
Aug 11, 2022

Conversation

drewbrend
Copy link
Contributor

@drewbrend drewbrend commented Jan 13, 2022

fixes #1316

What:

Fixing the handling of undefined/null being provided to useMultipleSelection's removeSelectedItem function.

Why:

Currently when undefined/null is provided one of the items is duplicated in selectedItems

How:

Only modifying the selectedItems and activeIndex if selectedItemIndex is greater than or equal to zero

Checklist:

  • Documentation N/A
  • Tests
  • TypeScript Types N/A
  • Flow Types N/A
  • Ready to be merged

@drewbrend drewbrend changed the title fix removeSelectedItem adding duplicate items to selected items Fix: removeSelectedItem adding duplicate items to selected items Jan 13, 2022
@lveillard
Copy link

Hello! Not sure but i think this PR could fix this also:
#1355

Will try it once is good.
Anything we can do to speed up the merge?
Thanks!

@drewbrend
Copy link
Contributor Author

Hello! Not sure but i think this PR could fix this also: #1355

Will try it once is good. Anything we can do to speed up the merge? Thanks!

I don't think it will, downshift relies on the items being reference equal so you probably need to fix how you're handling/re-creating your items

@lveillard
Copy link

lveillard commented Jan 28, 2022

so we have to drop all the good immutability practices? Why not being dependent on the content of the array instead of it's reference? Replacing/deleting object properties may not be the best option...

Also the example 5 is broken even just by adding some initial choices, no need to manipulate the object with .map() to cause the error of multiplying selected items.

And also it only happens with the inside of the popper, removing badges works as expected, so maybe is more an issue with the example than downshift itself? 🤔

I personally was unable to understand where it comes from

@silviuaavram
Copy link
Collaborator

Hi! Will take a look at this and will merge if it's good to go. Thank you!

@lveillard
Copy link

Hello @silviuaavram would be lovely to get some news about this, I think this is creating some weird bugs like this one: #1355

@drewbrend
Copy link
Contributor Author

@lveillard this will prevent you from getting duplicated values but won't fix your issue, you need to provide an item referentially equal to one of the provided items

@silviuaavram
Copy link
Collaborator

Finally fixed the CI pipeline. Let's see what this PR.

Copy link
Collaborator

@silviuaavram silviuaavram left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great changes and tests, congrats!

I think we should rebase this with latest master, since it has been a while, do that small change and merge it.

Thank you again for your patience @drewbrend !

src/hooks/useMultipleSelection/reducer.js Outdated Show resolved Hide resolved
@drewbrend drewbrend requested a review from silviuaavram August 8, 2022 12:30
@silviuaavram silviuaavram changed the title Fix: removeSelectedItem adding duplicate items to selected items fix(useMultipleSelect): removeSelectedItem adding duplicate items to selected items Aug 8, 2022
@silviuaavram silviuaavram merged commit bf709b9 into downshift-js:master Aug 11, 2022
@silviuaavram
Copy link
Collaborator

@all-contributors please add @drewbrend for code

@allcontributors
Copy link
Contributor

@silviuaavram

I've put up a pull request to add @drewbrend! 🎉

@github-actions
Copy link

🎉 This PR is included in version 6.1.8 🎉

The release is available on:

Your semantic-release bot 📦🚀

@drewbrend drewbrend deleted the issue-1316 branch October 28, 2022 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

useMultipleSelection hook's removeSelectedItem incorrectly adds an item
3 participants