Skip to content

Move focus into schema-driven menus on open - #807

Open
etuan wants to merge 1 commit into
embedpdf:v2from
etuan:fix/schema-menu-focus-management
Open

etuan wants to merge 1 commit into
embedpdf:v2from
etuan:fix/schema-menu-focus-management

Conversation

@etuan

@etuan etuan commented Sep 11, 2026

Copy link
Copy Markdown

Summary

Opening a schema-driven toolbar dropdown (Zoom Menu, Document Menu, Page Settings, the tools overflow menus, ...) positions the menu but never moves focus into it. A keyboard-only user activating the trigger has no way to reach the menu's own items: focus stays on the trigger button, and continuing to press Tab skips over the (positioned, but never focused) menu entirely.

The menu container was also missing role="menu", even though each item already carries role="menuitem".

Fix

In DesktopMenu (viewers/snippet/src/ui/schema-menu.tsx):

  • Add role="menu" to the container div.
  • On mount, focus the first [role="menuitem"]:not([disabled]).
  • On unmount (Escape, outside click, or item selection), restore focus to the trigger element (anchorEl) instead of leaving it on a removed/hidden node.

Steps to reproduce (before this fix)

  1. Open a document.
  2. Tab to the Zoom Menu button and press Enter/Space to open it.
  3. Press Tab again — focus leaves the toolbar entirely instead of landing on the first zoom option.

WCAG 2.1.1 (Keyboard) — all functionality must be operable through a keyboard interface.

Known follow-up (not fixed here)

Navigating into a submenu does not move focus to the submenu's first item, since DesktopMenu is the same component instance across that transition (only currentMenu changes) rather than being remounted. I left this out rather than half-fix it — happy to open a follow-up PR for it if useful.

Testing

Manually verified per the repro steps above; no existing test suite for this package.

DesktopMenu positioned the menu but never moved focus into it, so a
Tab-only keyboard user activating a menu trigger (Zoom Menu, Document
Menu, Page Settings, ...) had no way to reach the menu's own items:
focus stayed on the trigger and the next Tab press continued past the
menu entirely. Also add the role="menu" the container was missing,
matching the role="menuitem" already set on each item.

Known gap left for a follow-up: navigating into a submenu does not
move focus to the submenu's first item, since DesktopMenu is not
remounted on that transition.
@vercel

vercel Bot commented Sep 11, 2026

Copy link
Copy Markdown

@etuan is attempting to deploy a commit to the CloudPDF Team on Vercel.

A member of the Team first needs to authorize it.

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.

1 participant