Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

mahoneycm
Copy link
Contributor

@mahoneycm mahoneycm commented Feb 21, 2023

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, and Space 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

  1. The combobox story or a page with a combobox component
  2. Navigate to the component using your keyboard
  3. Use the up and down arrows to make a selection
  4. Press tab to escape the combobox
  5. Check that the combobox is no longer selected and that no selection was made
  6. Return to the combobox and repeat step 3
  7. Press the spacebar
  8. Check that a selection was made

Before opening this PR, make sure you’ve done whichever of these applies to you:

  • Confirm that this code follows the 18F Front End Coding Style Guide and Accessibility Guide.
  • Run git pull origin [base branch] to pull in the most recent updates from your base and check for merge conflicts. (Often, the base branch is develop).
  • Run npm test and confirm that all tests pass.

@mahoneycm mahoneycm marked this pull request as ready for review February 21, 2023 19:28
@mahoneycm
Copy link
Contributor Author

@amyleadem @mejiaj

This issue was raised on USWDS-Site instead of USWDS. Should I create a duplicate issue and close the original?

@mahoneycm
Copy link
Contributor Author

Issue transferred to USWDS Repo! Thanks for the tip @amyleadem 🥇

@mahoneycm mahoneycm changed the title USWDS - Combobox: Keyboard selection compliance update. Resolves #1898 USWDS - Combobox: Keyboard selection compliance update. Resolves #5161 Feb 22, 2023
Copy link
Contributor

@mejiaj mejiaj left a 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.

Copy link
Contributor

@amyleadem amyleadem left a 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

@amyleadem amyleadem requested a review from thisisdano March 1, 2023 18:05
@thisisdano
Copy link
Contributor

thisisdano commented May 8, 2023

I'll draw up a changelog PR for this change.
Changelog PR: uswds/uswds-site#2096

@thisisdano
Copy link
Contributor

thisisdano commented May 8, 2023

Note that this resolves two of the issues in #5161 but not the type the same character to navigate through all options starting with the same letter issue, which I'm inclined to categorize as a feature request and not a bug. We should adapt #5161 into a new feature request and close the original issue with this PR.

[EDIT. Nevermind. I finally understand your original quote from the W3 spec.]

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

USWDS-Site - Bug: ComboBox

4 participants