Skip to content

fix(theme): make dropdown navbar items accessible via screen readers#11889

Open
GalacticAvenger wants to merge 1 commit intofacebook:mainfrom
GalacticAvenger:fix/dropdown-a11y-keyboard
Open

fix(theme): make dropdown navbar items accessible via screen readers#11889
GalacticAvenger wants to merge 1 commit intofacebook:mainfrom
GalacticAvenger:fix/dropdown-a11y-keyboard

Conversation

@GalacticAvenger
Copy link
Copy Markdown

Summary

Fixes the dropdown navbar item (language selector, doc version selector) to be accessible via screen readers.

Fixes #8478

Problem

Screen readers like NVDA and Windows Narrator fire a synthetic click event (not a keydown event) when the user presses Enter on a focused element. The previous onClick handler only called e.preventDefault() without toggling the dropdown, while the toggle logic lived exclusively in onKeyDown. This meant screen reader users could never open dropdown menus.

Changes

  • onClick now toggles the dropdown when there's no to prop (i.e., the element acts as a button, not a link). This ensures screen readers that fire synthetic clicks can open/close the menu.
  • Added Escape key support to close the dropdown, improving keyboard navigation.

Test plan

  • Open a Docusaurus site with NVDA/VoiceOver
  • Tab to a dropdown navbar item (e.g., language selector)
  • Press Enter — dropdown should open
  • Press Escape — dropdown should close
  • Mouse hover/click behavior unchanged

The onClick handler now toggles the dropdown instead of only calling
preventDefault(). Screen readers (NVDA, Narrator) fire a synthetic
click event instead of keydown when pressing Enter on focused elements,
so the previous code that only toggled in onKeyDown was bypassed.

Also adds Escape key support to close dropdowns.

Fixes facebook#8478
@meta-cla
Copy link
Copy Markdown

meta-cla bot commented Apr 2, 2026

Hi @GalacticAvenger!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@netlify
Copy link
Copy Markdown

netlify bot commented Apr 2, 2026

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit 5824398
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/69cec9ca6bbdd7000759ac98
😎 Deploy Preview https://deploy-preview-11889--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@meta-cla
Copy link
Copy Markdown

meta-cla bot commented Apr 2, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla bot added the CLA Signed Signed Facebook CLA label Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug(navbar): languages and doc version drop downs are inaccessible via the keyboard and screen reader

1 participant