Repository navigation
Description
Have you read the Contributing Guidelines on issues?
- I have read the Contributing Guidelines on issues.
Prerequisites
- I'm using the latest version of Docusaurus.
- I have tried the
npm run clearoryarn clearcommand. - I have tried
rm -rf node_modules yarn.lock package-lock.jsonand re-installing packages. - I have tried creating a repro with https://new.docusaurus.io.
- I have read the console error message carefully (if applicable).
Description
When navigating a docusaurus site via keyboard while using a screen reader (e.g. NVDA), tabbing to a button and hitting enter causes visible focus to be lost. This is due to https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-theme-common/src/hooks/useKeyboardNavigation.ts, which removes navigation-with-keyboard class when clicking, this works for keyboard navigation while not using a screen reader but when using a screen reader hitting enter instead activates mousedown events.
Adding the following css appears to fix the issue:
body:not(.navigation-with-keyboard) *:not(input):focus-visible {
outline: auto !important;
}Which as you can see uses the :focus-visible selector which keeps the outline even if the element sees a mousedown event it will maintain focus if the element was already focused by tabbing to it. If a user clicks on a button not focused it will not have a visible focus ring.
Reproducible demo
The live docusaurus site exhibits this behaviour so it can be used.
Steps to reproduce
- On windows activate NVDA
- Open your browser to https://docusaurus.io/docs
- Tab to the
collapsebutton besideGetting Startedin the sidebar - Hit the enter key
Expected behavior
Visible focus should be retained
Actual behavior
Visible focus is lost
Your environment
- Public source code: N/A
- Public site URL: https://docusaurus.io/docs
- Docusaurus version used: 3.8.1
- Environment name and version (e.g. Chrome 89, Node.js 16.4): N/A
- Operating system and version (e.g. Ubuntu 20.04.2 LTS): N/A
Self-service
- I'd be willing to fix this bug myself.
Activity
Huzaif-nabi commentedon Oct 17, 2025
I can reproduce this and would like to submit a pull request with the suggested fix.
slorber commentedon Oct 23, 2025
Can this be reproduced only on Windows with NVDA?
On macOS with VoiceOver I still see the focus ring on the sidebar item collapse buttons.
Is it related to using the screen reader, or can you reproduce in Windows by simply tab/enter without the screen reader being enabled?
Can you tell us which browser you are using and which version?
ericenns commentedon Jan 8, 2026
This can also be reproduced on Windows with JAWS
The issue only occurs when using the screen reader, as both NVDA and JAWS through the accesibility api trigger a
clickwhen hittingEnterkey.This occurs on all versions of Chrome and Edge, I haven't tested with Firefox.
nmggithub commentedon Feb 1, 2026
TL;DR:
I believe the
useKeyboardNavigationhook is poorly designed for the modern web. At best, it provides an aesthetic benefit by removing Chrome's own focus ring when users click non-input focused elements that don't navigate away. At worst, it negatively affect downstream styles (see: electron/website#1001) as well as screen readers that causemousedownevents to be emitted.I see two options:
:focus-visible(perhaps instead of listening to mouse events).Existing behavior
With VoiceOver
Below is a video of me using VoiceOver around the button discussed in the initial issue comment. As can be seen, both Chrome and VoiceOver itself add focus indicators. The first toggle is achieved by pressing
Enter. The second toggle is achieved by clicking. The click removes Chrome's focus ring (due to hook's CSS).Screen.Recording.2026-02-01.at.16.45.27.mov
Without VoiceOver (and removing the hook's styles)
If I remove the hook's styles, navigate to the same button with the keyboard, and click it, there does appear to be two focus indicators (blue and white) for different states:
Screen.Recording.2026-02-01.at.17.08.22.mov
Removing the hook's styles and testing out tabs (one of the original motivating components for these style changes), the look is less ugly than before. To note, in the below video, I clicked right outside the tabs, pressed the
Tabkey to select the first tab, and then click that first tab.Screen.Recording.2026-02-01.at.17.37.33.mov
Looking to the future
I think the
useKeyboardNavigationimplementation needs to be rethought. CSS pseudo-selectors like:focus-visibleprovide a much better API surface with which to handle focus rings. While listening tomousedownevents may seem like a good indication that the user is now using a mouse, it's not foolproof. Some screen readers / assistive technologies simulate mouse actions, thus causing events likemousedownto be fired even when the user actually isn't using a keyboard. That previously-linked article explicitly calls out how theEnterkey resulted in amousedownevent firing.The hook appears to have been made before
:focus-visiblewas widely supported (although there does appear to have been discussion about:focus-visiblein the issue that prompted the creation of what would eventually become the hook). Regardless, we're kind of fighting the browser (and sometimes downstream devs) with these style changes. A more thoughtful approach is warranted.slorber commentedon Feb 5, 2026
I agree with you @nmggithub, this hook is not ideal and was written at a time where
:focus-visiblewas early and afaik not widely supported.In #3626 I even proposed to use
:focus-visiblebut it was too earlyCan you confirm that moving to
:focus-withinwould fix the current windows-only problem? Do you want to submit a PR?Note: here's the original blog post because the link in code is broken: https://david-gilbertson.medium.com/removing-that-ugly-focus-ring-and-keeping-it-too-6c8727fefcd2
nmggithub commentedon Feb 5, 2026
@slorber Thanks for following up (and confirming that change might be needed)! I'll do some testing myself and see if I can come up with a better approach by using
:focus-visible(or maybe:focus-within, as you mentioned, but that may have been a typo).slorber commentedon Feb 6, 2026
@ericenns can you please test on our website docusaurus.io if you still encounter the windows screen reader problem above?
ericenns commentedon Feb 6, 2026
@slorber I tested docusuarus.io and I can confirm that visible focus is no longer lost while using either NVDA or JAWS screen readers on Windows with Chrome.
slorber commentedon Feb 6, 2026
awesome, thanks for confirming 👍