Repository navigation
fix(DropdownMenu, ContextMenu): Tab from any sub-menu level closes the whole menu - #8870
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
There was a problem hiding this comment.
Approval of this fix waits on an engineering owner's decision on the three draft requirements it adds (DropdownMenu FR22, ContextMenu FR11, DropdownMenuSubMenu FR10), because no current record states this Tab rule yet. An engineering owner records the decision by commenting /approve-spec <full head SHA> on this pull request, and the author may do so if they are an engineering owner. The DropdownMenu and ContextMenu change works as described and its new tests fail without the fix, but one change is needed either way:
BreadcrumbItemmenus render the same sub-menu, but their root still ignores keys from a flyout (BreadcrumbItem.tsx:582), so Tab on a breadcrumb sub-menu row now closes only the flyout and leaves focus on the page body with the menu open; giving that root the same Tab branch, with a test, would match BreadcrumbItem FR5 and FR6.
[Automated review]
| // In a menu with a header or footer above this level, that level | ||
| // moves focus on; in a plain menu the root closes the whole menu, | ||
| // and focus moves on from its trigger (APG menu button). | ||
| close({focusTrigger: false}); |
There was a problem hiding this comment.
This close now runs under every root that hosts DropdownMenuSubMenu, not only DropdownMenu and ContextMenu. BreadcrumbItem renders the same sub-menu (a nested items entry, or BreadcrumbMenuSubMenu), but its root still returns early for keys from a flyout (BreadcrumbItem.tsx:582). So Tab on a breadcrumb sub-menu row closes only the flyout and leaves focus on the page body with the breadcrumb menu open. Adding the same if (e.key === 'Tab') closeMenu(); branch to that root's non-owned path (BreadcrumbItem FR5 already says Tab closes its menu), with a test, would keep the three roots consistent.
|
/approve-spec 153d2d9 |
|
I'll run a full review to re-check this with your approval noted. |
a424847 to
7d5c40d
Compare
|
/approve-spec 7d5c40d |
PR Analysis Report🔎 Preview ·
|
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| Breadcrumbs | 16.1 kB (0) · 3.4 kB CSS (0) | — | ✓ · ✓ · ✓ |
| ContextMenuItem | 26.5 kB (0) · 6.1 kB CSS (0) | — | — · — · — |
| DropdownMenuCheckboxItem | 21.1 kB (0) · 6.4 kB CSS (0) | — | ✓ · ✓ · ✓ |
16 more components
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| DropdownMenuDivider | 5.2 kB (0) · 548 B CSS (0) | — | ✓ · ✓ · — |
| DropdownMenuGroup | 6.3 kB (0) · 3.4 kB CSS (0) | — | ✓ · ✓ · — |
| DropdownMenuItem | 20.4 kB (0) · 6.0 kB CSS (0) | — | ✓ · ✓ · — |
| DropdownMenuRadioGroup | 6.3 kB (0) · 3.3 kB CSS (0) | — | ✓ · ✓ · — |
| DropdownMenuRadioItem | 21.2 kB (0) · 6.4 kB CSS (0) | — | ✓ · ✓ · — |
| Table | 98.2 kB (−45 B) · 17.1 kB CSS (0) | — | — · — · — |
| ContextMenu · Storybook | 88.8 kB (−54 B) · 16.4 kB CSS (0) | 702 (+3) | ✓ · ✓ · ✓ |
| TableCell | 90.0 kB (−59 B) · 16.8 kB CSS (0) | — | — · — · — |
| DropdownMenuSubMenu | 64.3 kB (−62 B) · 9.4 kB CSS (0) | — | ✓ · ✓ · ✓ |
| TableHeaderCell | 89.6 kB (−62 B) · 16.6 kB CSS (0) | — | — · — · — |
| BreadcrumbItem | 75.6 kB (−65 B) · 11.4 kB CSS (0) | — | ✓ · ✓ · ✓ |
| Markdown | 160.0 kB (−73 B) · 19.3 kB CSS (0) | — | — · — · — |
| DropdownMenu | 85.3 kB (−77 B) · 16.5 kB CSS (0) | — | ✓ · ✓ · ✓ |
| MoreMenu | 85.6 kB (−78 B) · 16.5 kB CSS (0) | — | — · — · — |
| lab/Comments | 280.5 kB (new) · 2.5 kB CSS (new) | — | — · — · — |
| lab/CommentThread | 274.7 kB (new) · 2.4 kB CSS (new) | — | — · — · — |
Package size: measured; main has no measurement of the merge base to compare yet.
API changes: none in this pull request
Committed API report behind this build: cli 19 rows, core 23 rows; run pnpm api:report.
Touched components checked; add ci:run-visual, ci:run-a11y or ci:run-rtl to run the full suites.
Generated by PR Enrichment workflow | View full report
There was a problem hiding this comment.
Thanks for closing this keyboard gap. The engineering-owner approval at this head settles the new Tab rows, and in DropdownMenu and ContextMenu the change works as described: the new tests fail without the fix and pass with it. One change is needed before approval:
BreadcrumbItemmenus render the same sub-menu, but their root still ignores keys from a flyout (BreadcrumbItem.tsx:595), so Tab on a breadcrumb sub-menu row now closes only the flyout and leaves focus on the page body with the breadcrumb menu still open; giving that root the same Tab branch as the other two roots, with a Breadcrumbs test, would match BreadcrumbItem FR5 and FR6.
The fix makes a new commit, so an engineering owner needs to comment /approve-spec <full head SHA> again on the new head; the author can do this as an engineering owner. Three comment rewrites are suggested inline and are optional.
[Automated review]
| // In a menu with a header or footer above this level, that level | ||
| // moves focus on; in a plain menu the root closes the whole menu, | ||
| // and focus moves on from its trigger (APG menu button). | ||
| close({focusTrigger: false}); |
There was a problem hiding this comment.
This close now runs under every root that hosts DropdownMenuSubMenu, not only DropdownMenu and ContextMenu. BreadcrumbItem renders the same sub-menu (a nested items entry, or BreadcrumbMenuSubMenu), but its root still returns early for keys from a flyout (BreadcrumbItem.tsx:595). So Tab on a breadcrumb sub-menu row closes only the flyout and leaves focus on the page body with the breadcrumb menu open. Adding the same branch to that root's non-owned path keeps the three roots consistent and matches BreadcrumbItem FR5 and FR6:
if (!ownsEvent(e)) {
if (e.key === 'Tab') {
closeMenu();
}
return;
}A Breadcrumbs test for Tab on a flyout row would guard it.
| // Otherwise Tab leaves the flyout stack: every open level closes as | ||
| // the key bubbles past it, this one's own rows or a deeper level's. | ||
| // In a menu with a header or footer above this level, that level | ||
| // moves focus on; in a plain menu the root closes the whole menu, | ||
| // and focus moves on from its trigger (APG menu button). |
There was a problem hiding this comment.
Optional (comment style): the second sentence carries three topics in 33 words, and "the root closes the whole menu" is not yet true under BreadcrumbItem. A shorter version:
// Tab leaves the flyout stack. Each open level closes as the key passes it.
// The root, or a level above with a header or footer, then moves focus on.| // Except Tab: each open flyout has closed itself as the key bubbled | ||
| // up, and the root moves on as Tab from one of its own rows would. | ||
| // With a header or footer that walks the regions; otherwise the menu | ||
| // closes and focus moves on from the trigger (APG menu button). |
There was a problem hiding this comment.
Optional (comment style): one topic per sentence reads more easily here:
// Tab is the exception. Each open flyout has already closed itself.
// With a header or footer, the walk goes on through the regions.
// Otherwise the menu closes, and focus moves on from the trigger.| // Except Tab: each open flyout has closed itself as the key bubbled up, | ||
| // and the menu closes as Tab from one of its own rows would (APG). |
There was a problem hiding this comment.
Optional (comment style), split into one fact per sentence:
// Tab is the exception. Each open flyout has already closed itself,
// so the menu closes as for Tab on its own row.|
/approve-spec e6face5 |
There was a problem hiding this comment.
Thanks for the follow-up. BreadcrumbItem menus now close on Tab from a sub-menu row the same way DropdownMenu and ContextMenu do, and the engineering-owner approval at this head settles the new Tab rows. The new tests fail without the fix and pass with it, and in a real browser Tab from a flyout row closes every level and moves focus on in all three menus.
Approved pending CI: the required build, test and docsite-test suites are deferred on this push and run before merge; lint and typecheck pass.
One optional comment-style suggestion is inline.
[Automated review]
| // Except Tab: each open flyout has closed itself as the key bubbled up, | ||
| // and the menu closes as Tab from one of its own rows would (APG). |
There was a problem hiding this comment.
Optional (comment style): this is one 27-word sentence with two topics. A shorter version:
// Tab is the exception. Each open flyout has already closed itself,
// so the menu closes as for Tab on its own row.There was a problem hiding this comment.
Approved pending CI: the required build, test and docsite-test suites are deferred on this push and run before merge; lint, typecheck and the CLI smoke test pass.
The new commit removes the deleted menuRegionsContext module from the CLI's recorded module names, so the resolution test matches the source again; nothing else changed since the last review. Tab or Shift+Tab on a sub-menu row still closes every level of DropdownMenu, ContextMenu and BreadcrumbItem menus, and the engineering-owner approval of the new Tab rows holds on this head. The optional comment-style suggestions from earlier stay inline.
[Automated review]
…opdownMenu FR23 (main's FR22 is the entrance hold)
|
/approve-spec 655a76d |
There was a problem hiding this comment.
Requesting one small change before approval.
- Miss: the changeset (
.changeset/submenu-tab-closes-menu.md, line 5) says Tab from a sub-menu flyout row now closes everyDropdownMenu, but aDropdownMenuwith its ownheaderorfooterstill closes only the flyout and moves to its footer with the menu open, as before (the existing "Tab from a flyout row closes the flyout and moves to the footer" test asserts this), so please scope the note to menus without aheaderorfooterand end it with "A menu or sub-menu with aheaderorfooterkeeps its Tab cycle."
The fix itself looks right: the new tests fail without the change and pass with it, and the new Tab rows (DropdownMenu FR23, ContextMenu FR11, DropdownMenuSubMenu FR10) carry an engineering owner's approval for this revision. The optional comment-style suggestions from earlier stay inline.
[Automated review]
| '@astryxdesign/core': patch | ||
| --- | ||
|
|
||
| [fix] `DropdownMenu`, `ContextMenu` and `BreadcrumbItem` menus: Tab or Shift+Tab on a row inside an open sub-menu flyout now closes every open level and the menu, calls `onOpenChange(false)` once, and lets focus move on from the trigger, as Tab already did from a top-level row (WAI-ARIA Menu Button). Before, the menu stayed open. A sub-menu with a `header` or `footer` keeps its Tab cycle. |
There was a problem hiding this comment.
This note reads as if every DropdownMenu changed, but a menu with its own header or footer still closes only the flyout on Tab and moves to its footer with the menu open, as before (the existing "Tab from a flyout row closes the flyout and moves to the footer" test in DropdownMenu.test.tsx). A scoped version:
[fix] `DropdownMenu`, `ContextMenu` and `BreadcrumbItem` menus without a `header` or `footer`: Tab or Shift+Tab on a row inside an open sub-menu flyout now closes every open level and the menu, calls `onOpenChange(false)` once, and lets focus move on from the trigger, as Tab already did from a top-level row (WAI-ARIA Menu Button). Before, the menu stayed open. A menu or sub-menu with a `header` or `footer` keeps its Tab cycle.
|
/approve-spec 831d715 |
There was a problem hiding this comment.
Approved pending CI: the deferred build, typecheck and test suites have not run on this head yet; they run before merge.
Thanks for tightening the changeset. It now scopes the note to menus without a header or footer, which matches the new DropdownMenu FR23 row and the header-and-footer tests. The Tab rows (DropdownMenu FR23, ContextMenu FR11, DropdownMenuSubMenu FR10) carry an engineering owner's approval for this head, and the BreadcrumbItem branch follows its existing FR5 ("Escape, Tab, and selection close it"). The five new tests fail on main and pass here, and the header and footer suites still pass.
The earlier comment-style suggestions on the new source comments stay optional.
[Automated review]
…ses-all # Conflicts: # docs/specs/components/DropdownMenu/DropdownMenu.spec.md
|
/approve-spec 40e1627 |
There was a problem hiding this comment.
Approved pending CI: lint and the CLI smoke test pass on this head, but the build and test suites have not run yet; their first attempt found no room under the CI ceiling and the re-run is still waiting.
Tab or Shift+Tab on a sub-menu flyout row now closes every level of a DropdownMenu, ContextMenu or BreadcrumbItem menu without a header or footer, and the new tests fail without the change. The DropdownMenu FR23 (the description still calls it FR22), ContextMenu FR11 and DropdownMenuSubMenu FR10 rows are approved for this head, and the breadcrumb branch matches BreadcrumbItem FR5. The comment-style suggestions on the earlier inline threads remain optional.
[Automated review]
…ords: this stack's FR11/FR12 renumbered to FR12/FR13 after meta#8870's FR11)
…ords: this stack's FR11/FR12 renumbered to FR12/FR13 after meta#8870's FR11)
…ords: this stack's FR11/FR12 renumbered to FR12/FR13 after meta#8870's FR11)
…en pointer types, and judge a press in a closed shadow root (#9814) * test(Layer): the outside-press watch can follow chosen pointer types, close on a pan, and judge a press inside a shadow root - A watch given pointer types ignores other pointers. - A watch that closes on a pan closes as a press that starts outside pans past the pan threshold, measured on each axis and beginning at the threshold itself, or when the browser takes the press. A second finger waits for the first. - A watch given a shadow root judges a press inside that root there, since the document sees a press in a closed root as a press on its host. * feat(Layer): the outside-press watch follows chosen pointer types, closes on a pan, and judges a press inside a shadow root watchOutsidePress and useOutsidePress take options: - pointerTypes: the pointer types the watch follows; every type when omitted. - closesOnPan: a press that starts outside also closes the layer as it begins to pan (the larger axis reaches core's pan threshold) or when the browser takes it. Only the first pointer counts. Its moves come through core's input stream. - root: the shadow root the layer renders in judges a press after the document, so a press inside a closed root stays inside. Callers that pass no options keep today's watch. * test(Layer): a closed shadow root judges a lift on its layer, and an unfollowed pointer's cancel leaves a followed press alone - A press that starts outside and lifts on a layer inside a closed shadow root keeps it open, as it does a light-DOM or open-root layer, with or without the pan close. The document sees that lift on the root's host. - A pointercancel from a pointer type the watch does not follow (a pen while it follows touch) leaves a followed press as it was, so that press's lift outside still closes the layer. * fix(Layer): a closed shadow root judges a lift inside it before its host does, and an unfollowed pointer's cancel is ignored - The document and the host see a lift inside a closed root as a lift on the host. So the root judges a lift inside it on the way down, and the host judges, on the way back up, a lift the root did not: one on the host itself. A press that starts outside and lifts on the layer keeps it open, as it does a light-DOM or open-root layer. - pointercancel follows the watch's pointer types, as its press and lift do. - The pan's start point has its own name, the onOutside JSDoc names the pan close, and the file header names the root and the pan moves. * test(Layer): the outside-press watch keeps a closed root's layer open inside other closed roots and in another window A press that starts outside and lifts on the layer must not close it when the layer's closed root sits inside another closed root, where the document sees the lift on the outer host, or when the root comes from a same-origin iframe, whose shadow roots are not this window's ShadowRoot. The shared shadowHostOf helper must find such a root's host too. * fix(Layer): the outside-press watch judges a closed root's lifts through the outermost host, in any window - shadowHostOf checks the node type, not instanceof ShadowRoot, so a shadow root from a same-origin iframe or a Picture-in-Picture window has a host and gets its root listener. - The new outermostShadowHostOf walks up to the host the document sees. The document's skip test and the host listener use it, so a lift on a layer whose closed root sits inside other closed roots is judged by the root, and a lift on the outer roots' other content by that host. - The closesOnPan JSDoc says other pointers are ignored while a press outside is followed. * test(Layer): a lift on an outer closed root's control that stops it still closes, and a new primary pointer is followed In nested closed roots, a control in the outer root whose pointerup handler stops propagation must not keep its lift from closing the layer, nor leave the watch following that press. A new primary pointer starts a new press when the followed press's lift never reached the document. * fix(Layer): every shadow root out to the document judges a lift in the capture phase, and a new primary pointer starts a new press - utils/flatTree's shadowRootsOutward lists the roots from a given root out to the document, each with its host; it replaces outermostShadowHostOf. - The document and each of those roots judge a lift in the capture phase, each skipping a lift whose path holds the host below it; the innermost root judges every lift it sees, and each host a lift on itself. So a control in an outer closed root that stops its pointerup no longer keeps the lift from closing the layer. Each root also judges a press's start. - With closesOnPan, a new primary pointer starts a new press, so a press whose lift never reached the document does not make the watch ignore every later touch. - isWithinLayer walks with shadowHostOf, and the private isShadowRoot goes. - Comments follow the comment style; the file header keeps main's text. * refactor(utils): the selection lock walks shadow roots through flatTree's helpers The selection lock's open-root walk keeps the open roots of shadowRootsOutward, and its host lookup for text under a shadow root calls shadowHostOf, so core has one shadow-root walk and one host check. Behavior is unchanged. The flat-tree header names the outside-press watch among its users, and a comment that restated a helper goes. * chore(Layer): the changeset names a closed shadow root, and the outside-press header keeps only its tags A press inside an open shadow root was already judged on its composed path, so the changeset now says the watch judges a press inside a closed shadow root, which the document sees as its host. The file header drops its prose, which said a cancelled press is forgotten: with `closesOnPan` a cancel closes the layer, and `watchOutsidePress`'s JSDoc states the rule. * test(Layer): a layer the outside-press watch closes on a pan or a cancel counts as an outside dismissal The per-document dismissal count (#9988) keeps a modal host open when the press on its backdrop closed a layer above it. A layer the watch closes as a press outside begins to pan, or when the browser takes that press, is such a dismissal too, as one it closes at a lift is. The case fails until the next commit. * fix(Layer): a layer the outside-press watch closes on a pan or a cancel counts as an outside dismissal `close`, which the pan and the cancel take, records the dismissal before it calls `onOutside`, as the lift does. So a modal host's backdrop press beneath a layer that closed that way keeps the host open. * Merge branch 'main' into uikit/c20-outside-pan-watch * Merge main into the ContextMenu long-press base branch (#8870 landed) * docs(Layer): split two long file-header sentences The headers of `outsidePress.ts` (`@output`) and `flatTree.ts` (`@position`) ran past INV29's sentence length. Each now says one thing per sentence. Comments only. * Merge commit '79cc4ac7784906b9cdc72a21a74241a8fcd666f9' into HEAD * refactor(utils): shadowHostOf uses nodeType's isShadowRoot `utils/nodeType.ts` now holds the cross-window shadow-root check, so `shadowHostOf` uses it and the flat tree has one shadow-root test. * Merge commit 'a2234c02c241cfba6f90217fa7745f3157009af3' into HEAD * Merge commit '6cbcbf846bc94f1cd23e1d053488ccf3b54a24fb' into HEAD Co-authored-by: Cindy Zhang <[email protected]>
Fixes #8840
User impact
A keyboard user in a
DropdownMenuorContextMenusub-menu flyout who presses Tab expects to leave the menu, as Tab does from a top-level row. Instead the menu stays open and focus stays on the flyout row, so the person has to press Escape once per level before they can move on. After this change Tab or Shift+Tab from a row at any level closes every level and the menu, and focus moves on from the trigger in page order.Problem and solution fit
ownsEventis false), andDropdownMenuSubMenu's handler only closes itself on Tab when a header or footer sits above it.The fix completes the existing bubbling design:
DropdownMenuorContextMenu, seeing a Tab from a flyout, closes as it does for its own rows;Expected behavior and authority
Smallest restoration
DropdownMenuSubMenu: a Tab on a level without its own regions closes that level (close({focusTrigger: false})), whatever sits above it.DropdownMenuandContextMenuroots: a Tab from a flyout closes the menu, or walks the regions when the root has them, as before.MenuRegionsContexthad no reader left. It only told a flyout whether a level above had regions, so the second commit removes it.Evidence
Real Chrome 156 (headless), Storybook from
mainand from this branch, same keyboard probe. Tab to the trigger, Enter, ArrowDown to the sub-menu row, ArrowRight into the flyout, then Tab:mainafter Tab in the flyoutmain:DropdownMenuSubMenu.test.tsx"Tab from a flyout leaves the whole menu": one level, Shift+Tab, two levels. Each checks every level closed,onOpenChange(false)once, focus on the trigger, and the Tab not prevented.ContextMenu.test.tsxmatching case.Scope
Testing
pnpm vitest runfor DropdownMenu, ContextMenu and MoreMenu: 412 pass.tsc --noEmitfor core, eslint, prettier,pnpm check:knowledge,pnpm check:sync.Writing rubric results
Carry onto main (conflict-only)
Rebased onto main, keeping both commits. The only conflicts: main moved the ContextMenu, DropdownMenu and DropdownMenuSubMenu specs to
docs/specs/components/and reshaped their requirement tables to ID | Invariant | Basis. The same rows are re-applied there:The old draft-review-state column ("Decided; verified in jsdom") has no place in the new tables, so it is dropped. Code, tests and changeset are unchanged. DropdownMenu and ContextMenu tests: 427/427.
git range-diff (old 153d2d9 → new 7d5c40d)