Skip to content

fix(theme): use native dialog element for mobile sidebar#12165

Open
MasterIfeanyi wants to merge 1 commit into
facebook:mainfrom
MasterIfeanyi:fix/mobile-sidebar-native-dialog
Open

fix(theme): use native dialog element for mobile sidebar#12165
MasterIfeanyi wants to merge 1 commit into
facebook:mainfrom
MasterIfeanyi:fix/mobile-sidebar-native-dialog

Conversation

@MasterIfeanyi

Copy link
Copy Markdown
Contributor

Pre-flight checklist

  • I have read the Contributing Guidelines on pull requests.
  • If this is a code change: I have written unit tests and/or added dogfooding pages to fully verify the new behavior.
  • If this is a new API or substantial change: the PR has an accompanying issue (closes #0000) and the maintainers have approved on my working plan.

Motivation

The mobile sidebar looks like a modal dialog visually, but it was not behaving like one for assistive technologies. Screen reader users could tab outside the dialog while it was open, focus was not trapped inside, and the dialog role was not exposed to the accessibility tree.

This replaces the outer <div> with a native HTML <dialog> element using showModal(), which gives us focus trapping, correct dialog role in the accessibility tree, Escape key handling, and return focus to the trigger element — all for free from the browser.

Closes #9457.

Test Plan

On a mobile viewport or by zooming in on desktop:

  1. Open the mobile sidebar by clicking the hamburger menu
  2. Verify the sidebar is announced as a dialog by a screen reader
  3. Verify that Tab key cannot move focus outside the sidebar while it is open
  4. Verify that pressing Escape closes the sidebar
  5. Verify that clicking the backdrop closes the sidebar
  6. Verify that focus returns to the hamburger button after closing
  7. Verify the drawer animation still works as before

Test links

Deploy preview: https://deploy-preview-_____--docusaurus-2.netlify.app/

Related issues/PRs

Closes #9457
Related to #10706 (previous attempt at this fix)

@meta-cla meta-cla Bot added the CLA Signed Signed Facebook CLA label Jun 13, 2026
@netlify

netlify Bot commented Jun 13, 2026

Copy link
Copy Markdown

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit 697156b
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/6a2d47d40605460008e5c620
😎 Deploy Preview https://deploy-preview-12165--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.

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.

Modal dialog for menu on small viewports

1 participant