-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[ListboxUnstyled] Fix option state highlighted to prevent unnecessary focus #35838
Conversation
|
I updated the broken link test of the fix: https://codesandbox.io/s/fix-listbox-uvx06z?file=/demo.js |
Thanks for the fix. Would you mind adding a test to verify the behavior? |
…m is the only one that receive focus
@michaldudak done check it out 😉 |
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.
This looks good. Thanks for your contribution!
close #35780
This fix the bad focus on options when the list is initialized, In this case the findIndex will always return -1 for the index of the option because the array options is not filled yet.
before: https://codesandbox.io/s/k0zipv?file=/demo.js:0-1083
after: https://codesandbox.io/s/fix-listbox-uvx06z?file=/demo.js
Problem
highlighted: highlightedIndex === index, // this will be always true as long as the options array is empty
Fix
Force condition by checking index is not equal to -1 when the options is empty