Skip to content

fix(DropdownMenu): a field or button a menu hosts beside its rows keeps its own keys - #7309

Merged
cixzhang merged 1 commit into
meta:mainfrom
vjeux:menu-hosted-field-keys
Oct 11, 2026
Merged

cixzhang merged 1 commit into
meta:mainfrom
vjeux:menu-hosted-field-keys

Conversation

@vjeux

@vjeux vjeux commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

User impact

A field a menu hosts beside its rows, such as a filter, cannot be typed in: each letter moves focus to a matching row, and Space then picks it. Home, End and the arrows rove the rows, and a hosted button cannot be pressed from the keyboard. ContextMenu and sub-menu flyouts share this.

Problem and solution fit

  • Why it occurs: the menus' keydown handlers take every key from inside the menu: typeahead cancels printable keys, Enter and Space are cancelled as row activation, and arrows, Home and End rove the rows.
  • Why it harms the task: builders must stop every keydown on the control.
  • Why it matters: compound menus host such controls in DropdownMenu, ContextMenu and sub-menus.

A key pressed in a control the menu hosts outside every row is now that control's.

Expected behavior and authority

architecture:interaction-modality (current) INV4: every modality has an operable path. component:DropdownMenu and component:ContextMenu are drafts; this PR amends their keyboard rows (FR12, FR8).

Smallest restoration

  • Enter and Space activate rows only; on a hosted control they are not cancelled.
  • Typeahead skips keys typed into a hosted text field.
  • The menus turn on useListFocus's existing caret guard, so arrows, Home and End leave a text field only at the edge of its text.
  • In a hosted field, a sub-menu's close key (Left) moves the caret.

Rows, Tab and Escape are unchanged; a control inside a row still belongs to the row. No API or default change.

Evidence

  • Before, in real Chromium on a new HostedField story: typing "bu g" picks "Bug" and closes the menu; Enter on the hosted button leaves its counter at 0.
  • After: the field reads "bu g", Home moves the caret, ArrowDown from the end focuses the first row, and Enter and Space press the button.
  • Regression proof: five of six new unit cases fail on main (the Escape and typeahead guard passes); both Chromium cases fail against a main build.
  • Out of scope: arrows reaching into a hosted field.

Writing rubric results

R1 narration: FR12 and FR8 are present tense.
R2 research: none.
R3 evidence: the verification rows name the tests.
R4 rejected alternatives: none.
R5 change references: none.
R6 open questions: none.

Scope

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Testing

pnpm exec vitest run packages/core/src/DropdownMenu/DropdownMenu.test.tsx packages/core/src/ContextMenu/ContextMenu.test.tsx \
  packages/core/src/DropdownMenu/DropdownMenuSubMenu.test.tsx \
  -t "keys in a control the menu hosts|field the menu hosts beside its rows|field the flyout hosts"
  main's menus: 5 failed, 1 passed (Escape/typeahead guard) · with the change: 6 passed

pnpm exec vitest run packages/core/src/DropdownMenu packages/core/src/ContextMenu packages/core/src/Selector \
  packages/core/src/hooks/useListFocus.test.tsx packages/core/src/hooks/useTypeahead.test.tsx \
  packages/core/src/docPropLiterals.test.ts packages/core/src/docPropReferences.test.ts --maxWorkers=8
  Test Files  12 passed (12)   Tests  556 passed (556)

pnpm storybook:build   (once with main's four menu sources for the red arm)
ASTRYX_STORYBOOK_DIR=<red build> pnpm exec playwright test \
  packages/core/src/DropdownMenu/__tests__/MenuHostedField.a11y.chromium.spec.ts --project=chromium
  2 failed   (field gone after "bu g"; counter Received "0")
pnpm exec playwright test MenuHostedField MenuPress DropdownMenuDrillIn (.a11y.chromium.spec.ts) --project=chromium
  17 passed · MenuHostedField --repeat-each=3: 6 passed

pnpm -F @astryxdesign/core typecheck, CI=true eslint, prettier --check, check:knowledge, check-changesets, check-sync   ✓

…ps its own keys

The menus' keydown handlers took every key from inside the menu: typeahead
cancelled printable keys, Enter and Space were cancelled as row
activation, and arrows, Home and End roved the rows, so a field hosted in
a DropdownMenu, ContextMenu or sub-menu could not be typed in and a hosted
button could not be pressed from the keyboard. Enter and Space now
activate rows only, typeahead skips a hosted text field, the menus turn on
useListFocus's caret guard, and a hosted field keeps a sub-menu's Left
key. Rows, Tab and Escape are unchanged.
@vercel

vercel Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
astryx Ready Ready Preview Oct 10, 2026 4:59pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 10, 2026
@astracat-bot

astracat-bot Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 10, 2026, 5:33 PM UTC

@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

No new or modified components detected.

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.9KB 1.2KB

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

26 of 448 shot(s) changed.

A change here is a question, not a failure: check whether the after is the
picture you intended. Record that review on the PR. Baseline maintenance is an
explicit dispatch of CI; this report never rewrites the baseline or adds a release gate.

component story theme mode pixels
Selector Indicator Space Bottom Sheet Narrow End RTL neutral light 754,077
Selector Indicator Space Bottom Sheet Wide Start neutral light 740,188
Chat Full AI Chat probe light 155,733
Chat Full AI Chat probe dark 155,005
Chat Default neutral dark 33,205
Chat Default neutral light 32,876
Chat Empty State probe light 23,531
Chat Empty State probe dark 22,622
ChatAutoScroll Scroll Behavior Comparison neutral dark 15,378
ChatAutoScroll Scroll Behavior Comparison neutral light 14,107
Chat With Attachments probe light 13,229
Chat With Attachments probe dark 11,065
TableRowExpansion Detail Panel neutral dark 5,129
TableRowExpansion Detail Panel neutral light 4,050
SideNav Resizable in AppShell probe dark 3,208
SideNav Resizable in AppShell probe light 3,208
TableGroupedRows Default neutral light 2,133
TableGroupedRows Default neutral dark 2,116
Markdown Default probe dark 897
Markdown Default probe light 897

and 6 more.


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

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you — this cleanly fixes a real dead end: a filter field or action button composed inside one of these menus can now actually be used from the keyboard.

What I verified: typed text and Space stay in a hosted field in DropdownMenu, ContextMenu, and a sub-menu flyout; caret keys stay in the field until the text edge, where focus hands back to the rows; Enter and Space press a hosted button; and rows, typeahead, Tab, and Escape behave exactly as before, including controls nested inside a row. The new cases and the surrounding menu, Selector, and hook suites pass, and the HostedField story behaves as described in real Chromium.

Two small things worth a maintainer's eye, neither blocking this fix: axe flags the composed menu for containing a textbox and a button as aria-required-children, so it may be worth deciding what ownership anatomy the docs should bless for hosted controls; and a hosted native select gets its Enter/Space back but its arrow and printable keys still rove the rows, which could be a follow-up if that composition matters.

No public API or default changes, and the changeset looks right. Happy to see this land.

[Automated review]

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeBunny approved at this head; CI green. Approved.

@cixzhang
cixzhang enabled auto-merge (squash) October 11, 2026 17:14
@cixzhang
cixzhang merged commit 0f2d2ed into meta:main Oct 11, 2026
43 checks passed
@vjeux
vjeux deleted the menu-hosted-field-keys branch October 11, 2026 17:23
cixzhang added a commit that referenced this pull request Oct 11, 2026
…#7338)

* revert: menus no longer special-case controls placed among their rows

Reverts #7309 before it ships. A menu holds only menu items: role="menu"
admits menuitem, menuitemcheckbox, menuitemradio, groups and separators, so
a text field or button placed among the rows is invalid structure. Teaching
the menus' key handling to step aside for those controls made that structure
work instead of fixing it.

Removes the hosted-control key handling from DropdownMenu, ContextMenu and
the sub-menu flyout, the HostedField story and its tests, the FR12 and FR8
rows it added to the DropdownMenu and ContextMenu records, and its pending
changeset. Unreleased, so no caller is affected. Controls that belong beside
a menu's rows go outside the role="menu" element; a header/footer region for
that follows separately.

Original change by vjeux.

* chore: changeset for the menu hosted-control revert

This branch was successfully deployed

1 active deployment
Preview — ee689609 Deployed Oct 10, 2026 by vercel[bot]
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.

2 participants