Skip to content

A11y: Elements lose visible focus when using a screenreader and hitting Enter to activate #11314

Open
@ericenns

Description

@ericenns

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and 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

  1. On windows activate NVDA
  2. Open your browser to https://docusaurus.io/docs
  3. Tab to the collapse button beside Getting Started in the sidebar
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn error in the Docusaurus core causing instability or issues with its executiondomain: a11yRelated to accessibility concerns of the default theme

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions