-
Notifications
You must be signed in to change notification settings - Fork 1.1k
USWDS - Combobox: Keyboard selection compliance update. Resolves #5161 #5160
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
Conversation
This issue was raised on USWDS-Site instead of USWDS. Should I create a duplicate issue and close the original? |
Issue transferred to USWDS Repo! Thanks for the tip @amyleadem 🥇 |
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.
Looks good! I didn't encounter any issues with selecting items from the dropdown box via Spacebar. I also tested usa-time-picker as well because it relies on combobox and everything looked good there.
Thanks for updating the unit test too!
BTW, you don't need to add Resolves #
in the PR title as long as you have it in the body.
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.
Nice fix!
I was able to successfully perform the following tests:
- Run
npm start
,npm test
,npm run lint
,npm run prettier:js
without error - Confirm that
tab
closes the combo box and moves focus to the next element -
shift
+tab
moves focus to the combo box input - Confirm that
space
selects an item - Confirm that
enter
selects an item - Confirm that
esc
closes the combo box and keeps focus on combo box - Confirm that typing letters opens combobox and filters relevant selections
- Confirm that VoiceOver reads as expected
- Confirm these same behaviors in Time picker
- Test keyboard/touch interaction in Safari, Firefox, Chrome, Edge, iOS
I'll draw up a changelog PR for this change. |
[EDIT. Nevermind. I finally understand your original quote from the W3 spec.] |
Summary
Updates Combobox JS to allow Tab and Spacebar keyboard inputs to operate as expected within combobox drowdowns
Breaking change
This is potentially a breaking change if developers instruct users to make a selection via tab.
Related issue
Closes USWDS-Site uswds/uswds#5161
Preview link
Combobox →
Problem statement
Keyboard users should expect consistent behaviour when navigating with a combobox component. Users should be able to use
Tab
to escape the combobox selection without making a choice, andSpace
to select the current highlighted option when within the dropdown menu.Currently, we include JS that captures the tab event and uses it to select a highlighted combobox option instead of escaping the element.
Pressing the spacebar currently causes the combobox to scroll, rather than selecting the highlighted element as expected.
Solution
I've replaced the Tab functionality with the Spacebar. Now both elements behave as expected when within the combobox dropdown menu
Testing and review
Before opening this PR, make sure you’ve done whichever of these applies to you:
git pull origin [base branch]
to pull in the most recent updates from your base and check for merge conflicts. (Often, the base branch isdevelop
).npm test
and confirm that all tests pass.