Skip to content

feat(menu): remove hasAutoFocus, always focus first item on open (APG)#3438

Merged
cixzhang merged 2 commits into
mainfrom
navi/feat/menu-always-autofocus
Jul 3, 2026
Merged

feat(menu): remove hasAutoFocus, always focus first item on open (APG)#3438
cixzhang merged 2 commits into
mainfrom
navi/feat/menu-always-autofocus

Conversation

@cixzhang

@cixzhang cixzhang commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Removes the hasAutoFocus prop from DropdownMenu, ContextMenu, and MoreMenu. Menus now always focus their first item on open — the correct APG menu-button behavior.

Why

The hasAutoFocus={false} escape hatch existed for showcase previews, but it violated APG and was the root cause of the audit's menus-2 finding: Table plugin context menus opened with hasAutoFocus={false}, so no item received focus, and the menu was unreachable by keyboard and undismissable via Escape (because the Escape handler sat on a menu element that never had focus). Other menu instances used the default (true) and were fine — the prop only existed to support a scenario that no longer applies (showcases now render into sandboxes that isolate focus).

Breaking change

Consumers passing hasAutoFocus={false} to a DropdownMenu, ContextMenu, or MoreMenu will get a TypeScript error. The fix is to remove the prop — the menu will auto-focus as it should.

Internal usePopover({hasAutoFocus: false}) calls (used by menus internally to prevent usePopover's generic first-focusable autofocus, since menus drive focus via their own focusFirst) are unchanged.

What was updated

  • DropdownMenu.tsx: removed prop + made focusFirst() unconditional.
  • ContextMenu.tsx: same.
  • MoreMenu.tsx: removed pass-through.
  • tableContextMenu.tsx: removed the hasAutoFocus={false} passes that caused menus-2.
  • 3 showcase blocks: removed hasAutoFocus={false}.
  • 3 .doc.mjs files: removed prop documentation.
  • DropdownMenu.test.tsx: removed the test asserting the old hasAutoFocus={false} behavior.

Verification

Typecheck + lint clean; 384 tests pass across DropdownMenu + ContextMenu + MoreMenu + the full Table suite (which exercises the table context menu). No regressions.

@vercel

vercel Bot commented Jul 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview, Comment Jul 3, 2026 5:03am

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 2, 2026
@cixzhang cixzhang marked this pull request as ready for review July 2, 2026 18:12
@nynexman4464

Copy link
Copy Markdown
Contributor

Looks reasonable but there's a build error preventing the preview site from building to test.

@josephfarina

Copy link
Copy Markdown
Contributor

Approving to unblock, but flagging before this lands: the build check is red. This removes the public hasAutoFocus prop from DropdownMenu/ContextMenu/MoreMenu, but there's still a callsite passing it — apps/docsite… actually packages/cli/templates/pages/shell-side-nav/page.tsx:145 renders <MoreMenu hasAutoFocus={false}>, which no longer type-checks and breaks the build. Also, since this is a breaking prop removal, it should ship a codemod per the breaking-change process (that would've caught the stray callsite via dogfooding). Worth fixing the callsite + adding the codemod before merge.

@cixzhang cixzhang force-pushed the navi/feat/menu-always-autofocus branch from d9bb858 to e278396 Compare July 2, 2026 22:54
github-actions Bot added a commit that referenced this pull request Jul 3, 2026
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

No new or modified components detected.

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.6KB 0B

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

cixzhang added 2 commits July 3, 2026 04:56
APG menu-button: a menu must focus its first item when it opens. The
hasAutoFocus={false} escape hatch left menus keyboard-unreachable and
undismissable (the audit's menus-2 root cause in the Table context menu path).
Removed from DropdownMenu, ContextMenu, MoreMenu.
@cixzhang cixzhang force-pushed the navi/feat/menu-always-autofocus branch from e278396 to 7342a97 Compare July 3, 2026 04:59
@cixzhang cixzhang enabled auto-merge (squash) July 3, 2026 05:04
@cixzhang cixzhang merged commit e0724f3 into main Jul 3, 2026
15 checks passed
github-actions Bot added a commit that referenced this pull request Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants