add keyboard navigation support to Listbox
WHY are these changes introduced?
These changes are introduced to improve accessibility and UX for the product options Listbox.
- Adds support for selecting items in the Listbox using keyboard navigation.
- Reduces first input delay by updating the listbox state immediately rather than waiting for the navigation event.
WHAT is this pull request doing?
- Separates the listbox code into a separate JSX component.
- removes
LinkandonClickhandler, in favour of the Listbox'sonChangehandler, providing native support for keyboard navigation. - Removes
closeRefand manages the Listbox state withuseState, allowing selected option in the Listbox button to update immediately rather than after the route change has occurred. Maybe this should instead be handled optimistically but I am not sure..
If there is anything that you'd like to see done differently, please let me know and I will update the change accordingly.
HOW to test your changes?
- Go to any product with a Listbox element; i.e a product with a product option that has more than 7 possible values. For example, The Hydrogen Snowboard (
/products/snowboard). - Select new options for the Listbox using both keyboard navigation and clicks.
- Observe route change; add products to cart and review that new selected option is added to the cart.
Checklist
- [x] I've read the Contributing Guidelines
- [x] I've considered possible cross-platform impacts (Mac, Linux, Windows)
- [ ] I've added a changeset if this PR contains user-facing or noteworthy changes
- [ ] I've added tests to cover my changes
- [ ] I've added or updated the documentation
I have signed the CLA!
On second thought, maybe I should limit the scope of changes to adding support for keyboard navigation.. Remove the other stuff.
It's nice that the listbox is responds instantly to the user's selection but it should probably just update alongside the other variants and price.
Separating the listbox into a separate component is also probably an unnecessary abstraction here.
Updating the PR now
therealchrisrock since we move demo store to a different repo. I am going to close this. Feel free to open again on https://github.com/Shopify/hydrogen-demo-store (I truly wish github have a feature where I can move it over 🙏 )