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

[Menubar] Adds keyboard behaviors to the menubar, improves accessibility #3320

Open
wants to merge 82 commits into
base: develop
Choose a base branch
from

Conversation

tespin
Copy link
Contributor

@tespin tespin commented Jan 17, 2025

Fixes #2933

Just setting this up to track next steps for the component! This PR focuses on adding proper keyboard behaviors to the recently refactored Menubar. Currently in progress


Update

The Menubar component now has keyboard navigation and enhanced accessibility support. There are some other improvements to make which are listed at the end, but I'll implement them in future PRs seeing as this one has gotten rather large.

Before:
Navigation happened purely through Tab / Shift + Tab. Escape functionality worked but otherwise behaviors were not intuitive or accessible. Focus is not tied to state.

old_menubar_2.mov

After:
Most keyboard behaviors from the WAI ARIA authoring guide implemented. Tab behavior works as expected and initial focus styles are available.

menubar_test.mov

Key Changes

  • Implemented roving tab index in Menubar.jsx for focus management
  • Updated aria roles, such as aria-orientation='horizontal'on Menubar and aria-labels where applicable
  • Navigation support, including:
    • Horizontal and vertical navigation
    • Home/end, enter/space support
    • Basic focus trapping in submenus
  • Improved HTML structure
    • wrapped Menubar in nav element
    • moved from div-based menubar to ul/li
    • Logo is moved outside of the nav, UserMenu is back in
    • left and right menu items now wrapped in ul elements with role=group
  • added SubmenuContext for managing submenu state
  • MenubarSubmenu supports listbox aria roles, such as with the options in LanguageMenu
  • basic tests checking for checking component renders, keyboard behavior, and aria roles
  • added keyboard styles
  • added basic JSDoc comments for components

To Do

  • testing:
    • test with screen readers
    • verify aria structure and role handling
  • errors:
    • focus is not properly entering certain modals
    • some timing issues with effects and blur/focus handlers
  • optimizations:
    • consider refactoring context structure
    • memoize index and menuItem calculations
    • menuItems and menuItemToId could probably be combined into a better data structure
    • consolidate the more complex state updates with useReducer
  • other features/improvements:
    • add support for matching focused menu item to pressed character key
    • complete focus styles
    • extract common logic into hooks
    • tests could be more thorough
    • implement better compound component pattern

I have verified that this pull request:

  • has no linting errors (npm run lint)
  • has no test errors (npm run test)
  • is from a uniquely-named feature branch and is up to date with the develop branch.
  • is descriptively named and links to an issue number, i.e. Fixes #123

@tespin tespin mentioned this pull request Jan 17, 2025
10 tasks
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Extract logo to header level for better semantic structure
  • Ensure arrow keys only cycle through menu items, excluding the logo

@tespin tespin marked this pull request as ready for review February 1, 2025 09:32
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.

Up/Down arrow keys not working on dropdown
2 participants