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

previousSelectedItemsRef.current is not updated #1535

Open
boris-brtan opened this issue Sep 4, 2023 · 3 comments
Open

previousSelectedItemsRef.current is not updated #1535

boris-brtan opened this issue Sep 4, 2023 · 3 comments

Comments

@boris-brtan
Copy link

boris-brtan commented Sep 4, 2023

}, [selectedItems.length])

in some special cases for multiple selection when we use setSelectedItems instead of addSelectedItem, it can happen that previousSelectedItemsRef.current is not updated because setSelectedItems sets the same amount of items but different.

Example

1, 2, 3, 4
set 2, 3
set 1, 4
but in previousSelectedItemsRef.current are still 2, 3
set 1, 2, 3
in previousSelectedItemsRef.current are 1,2,3 because length changed

@boris-brtan
Copy link
Author

boris-brtan commented Sep 24, 2023

is this something that can be fixed or do you need Pull Request to be created?

@silviuaavram
Copy link
Collaborator

It is a corner case, but still valid. On the other hand, the alternative would be to search for potentially removed items on every render. Any better suggestions?

Furthermore, this hook logic is to announce to screen readers when an item is removed. It needs a completely different logic in order to handle the case with setSelectedItems.

I am still thinking about a better way with the whole a11y screen reader announcements, since the current behaviour is not great. I will update once we figure out something.

@boris-brtan
Copy link
Author

tried something, it is not perfect however better than nothing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants