Skip to content

Prevent menu list from auto-expanding on Tab key navigation #918

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

AshmitSherigar
Copy link
Contributor

Fix: Prevent menu list from auto-expanding on Tab key navigation

Problem

When keyboard users navigate using the Tab key, the menu list would auto-expand after the "Menu" button lost focus. On small viewports, this leads to the menu expanding off-screen, making it inaccessible for keyboard and assistive tech users.
(See issue #915)

Solution

This PR ensures that the menu list only expands when explicitly activated by click or keyboard press, and does not auto-expand when focus leaves the "Menu" button. A keydown listener checks for Tab and closes the menu if focus moves outside.

Changes Made

  • Added a useEffect with a keydown event listener to detect when focus leaves the menu/button
  • If the menu is open and the new focus is outside both, it closes the menu

Accessibility Impact

  • Improves accessibility for keyboard users by preventing unexpected or hidden UI behavior
  • Keeps focus management clean and predictable

Closes #915

@AshmitSherigar
Copy link
Contributor Author

@coseeian could you review this PR

@coseeian
Copy link
Collaborator

When the menu button's aria-expanded attribute is set to false, screen readers can still access the navigation items (Reference, Tutorials, Examples, Contribute, Community, About) by tab key or browser mode, even though the menu list is visually hidden. These navigation items should be hidden from the accessibility tree and tab key sequence when the menu list is not visible.

@coseeian
Copy link
Collaborator

Additionally, in the desktop layout, pressing the Tab key from the top of the page, the third tab stop focuses an element that has no accessible name or label. It appears to be the menu button intended for the mobile layout. This button should also be completely hidden from both the accessibility tree and the tab sequence in desktop view.

@AshmitSherigar
Copy link
Contributor Author

@coseeian could u check it now maybe

@coseeian
Copy link
Collaborator

It works fine on mobile, but in the desktop layout, the third tab stop focuses an element with no accessible name or label—screen readers do not announce anything for this element. This element should be hidden from both the accessibility tree and the tab sequence in the desktop layout.

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.

[Menu] Menu list automatically expands on Tab key navigation but is not visible
2 participants