Repository navigation
fix(NavHeadingMenuItem): keep disabled rows focused and inert - #11416
Conversation
Guard consumer activation callbacks while preserving observation, parent menu events, and caller-owned label content. Keep focus across disabled router swaps through the shared focus hook without requiring forwarded DOM refs. Preserve existing tab order, keyboard navigation, and direct-ref consumers, with regression coverage for ref cleanup and Activity transitions.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| NavHeadingMenuItem | 🔴 19.5 kB (+2.4 kB) · 6.7 kB CSS (0) | — | ✓ · ✓ · ✓ |
| RadioListItem | 79.4 kB (+486 B) · 11.2 kB CSS (0) | — | — · — · — |
| Item | 21.5 kB (+468 B) · 6.2 kB CSS (0) | — | — · — · — |
84 more components
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| SelectorOption | 25.3 kB (+449 B) · 6.8 kB CSS (0) | — | — · — · — |
| CheckboxListItem | 83.3 kB (+444 B) · 12.6 kB CSS (0) | — | — · — · — |
| lab/TabBarMoreList | 105.5 kB (+441 B) · 1.8 kB CSS (0) | — | — · — · — |
| ListItem | 82.4 kB (+440 B) · 12.6 kB CSS (0) | — | — · — · — |
| DropdownMenuItem | 29.2 kB (+400 B) · 7.1 kB CSS (0) | — | — · — · — |
| DropdownMenuRadioItem | 30.1 kB (+398 B) · 7.6 kB CSS (0) | — | — · — · — |
| DropdownMenuCheckboxItem | 30.1 kB (+396 B) · 7.6 kB CSS (0) | — | — · — · — |
| lab/TransferList | 140.3 kB (+375 B) · 1.2 kB CSS (0) | — | — · — · — |
| DropdownMenuSubMenu | 81.4 kB (+339 B) · 11.0 kB CSS (0) | — | — · — · — |
| Selector | 122.1 kB (+338 B) · 19.7 kB CSS (0) | — | — · — · — |
| lab/VideoPlayer | 237.2 kB (+327 B) · 2.1 kB CSS (0) | — | — · — · — |
| PowerSearch | 320.9 kB (+326 B) · 27.3 kB CSS (0) | — | — · — · — |
| Table | 126.7 kB (+324 B) · 21.2 kB CSS (0) | — | — · — · — |
| lab/AudioPlayer | 239.6 kB (+321 B) · 1.8 kB CSS (0) | — | — · — · — |
| lab/CommentComposer | 187.7 kB (+318 B) · 1.9 kB CSS (0) | — | — · — · — |
| DropdownMenu | 133.7 kB (+317 B) · 19.8 kB CSS (0) | — | — · — · — |
| Markdown | 211.2 kB (+312 B) · 23.5 kB CSS (0) | — | — · — · — |
| TableCell | 108.3 kB (+312 B) · 20.2 kB CSS (0) | — | — · — · — |
| richtext/RichTextEditorToolbar | 317.5 kB (+304 B) · 454 B CSS (0) | — | — · — · — |
| MoreMenu | 134.0 kB (+299 B) · 19.8 kB CSS (0) | — | — · — · — |
| ContextMenu | 107.1 kB (+297 B) · 19.6 kB CSS (0) | — | — · — · — |
| lab/TransferListSelector | 152.3 kB (+297 B) · 1.4 kB CSS (0) | — | — · — · — |
| lab/MediaPlaybackRate | 229.8 kB (+296 B) · 1.5 kB CSS (0) | — | — · — · — |
| lab/MediaCaptionsButton | 229.8 kB (+295 B) · 1.5 kB CSS (0) | — | — · — · — |
| lab/MediaFullscreenButton | 229.8 kB (+295 B) · 1.5 kB CSS (0) | — | — · — · — |
| lab/MediaPlayButton | 229.8 kB (+295 B) · 1.5 kB CSS (0) | — | — · — · — |
| lab/MediaVolume | 229.8 kB (+295 B) · 1.5 kB CSS (0) | — | — · — · — |
| lab/MediaSeekButton | 229.8 kB (+294 B) · 1.5 kB CSS (0) | — | — · — · — |
| lab/MediaTime | 229.8 kB (+294 B) · 1.5 kB CSS (0) | — | — · — · — |
| lab/MediaTimeSlider | 229.8 kB (+294 B) · 1.5 kB CSS (0) | — | — · — · — |
| Pagination | 155.2 kB (+288 B) · 20.1 kB CSS (0) | — | — · — · — |
| ContextMenuItem | 39.6 kB (+287 B) · 7.3 kB CSS (0) | — | — · — · — |
| lab/Comments | 391.3 kB (+280 B) · 2.5 kB CSS (0) | — | — · — · — |
| lab/CommentThread | 384.2 kB (+280 B) · 2.4 kB CSS (0) | — | — · — · — |
| TreeList | 47.8 kB (+262 B) · 6.0 kB CSS (0) | — | — · — · — |
| TableHeaderCell | 108.2 kB (+261 B) · 20.0 kB CSS (0) | — | — · — · — |
| BreadcrumbItem | 103.5 kB (+255 B) · 14.0 kB CSS (0) | — | — · — · — |
| lab/Schedule | 119.5 kB (+161 B) · 3.9 kB CSS (0) | — | — · — · — |
| Typeahead | 95.4 kB (+7 B) · 14.4 kB CSS (0) | — | — · — · — |
| AlertDialog | 134.6 kB (+6 B) · 16.3 kB CSS (0) | — | — · — · — |
| TopNavHeading | 88.5 kB (+6 B) · 12.4 kB CSS (0) | — | — · — · — |
| TabList | 48.5 kB (+3 B) · 6.8 kB CSS (0) | — | — · — · — |
| TabMenu | 85.0 kB (+3 B) · 12.3 kB CSS (0) | — | — · — · — |
| Drawer | 58.5 kB (+1 B) · 8.7 kB CSS (0) | — | — · — · — |
| MultiSelector | 110.0 kB (+1 B) · 18.9 kB CSS (0) | — | — · — · — |
| lab/NavigationScreen | 86.6 kB (+1 B) · 1.5 kB CSS (0) | — | — · — · — |
| lab/NavigationStack | 86.6 kB (+1 B) · 1.5 kB CSS (0) | — | — · — · — |
| lab/TourStep | 97.3 kB (+1 B) · 691 B CSS (0) | — | — · — · — |
| AvatarGroup | 49.8 kB (0) · 6.1 kB CSS (0) | — | — · — · — |
| BottomSheet | 76.9 kB (0) · 7.8 kB CSS (0) | — | — · — · — |
| BottomSheetSwitcher | 19.6 kB (0) · 3.4 kB CSS (0) | — | — · — · — |
| ButtonGroup | 45.0 kB (0) · 3.7 kB CSS (0) | — | — · — · — |
| ChatLayout | 91.6 kB (0) · 11.7 kB CSS (0) | — | — · — · — |
| DateInput | 209.8 kB (0) · 19.0 kB CSS (0) | — | — · — · — |
| LayoutPanel | 22.4 kB (0) · 5.1 kB CSS (0) | — | — · — · — |
| Lightbox | 151.6 kB (0) · 12.3 kB CSS (0) | — | — · — · — |
| SideNav | 116.3 kB (0) · 12.6 kB CSS (0) | — | — · — · — |
| TableSelectionToolbar | 78.5 kB (0) · 14.6 kB CSS (0) | — | — · — · — |
| TimeInput | 182.2 kB (0) · 17.9 kB CSS (0) | — | — · — · — |
| Toolbar | 48.4 kB (0) · 8.6 kB CSS (0) | — | — · — · — |
| TopNavMegaMenu | 82.4 kB (0) · 13.1 kB CSS (0) | — | — · — · — |
| lab/CommentPin | 61.9 kB (0) · 1.2 kB CSS (0) | — | — · — · — |
| lab/TabBarItem | 3.9 kB (0) · 1.8 kB CSS (0) | — | — · — · — |
| ChatComposer | 91.2 kB (−1 B) · 13.5 kB CSS (0) | — | — · — · — |
| Collapsible | 30.1 kB (−1 B) · 4.5 kB CSS (0) | — | — · — · — |
| CommandPalette | 84.2 kB (−1 B) · 13.5 kB CSS (0) | — | — · — · — |
| NavHeadingMenu | 19.1 kB (−1 B) · 3.5 kB CSS (0) | — | ✓ · ✓ · ✓ |
| Tokenizer | 113.4 kB (−1 B) · 21.9 kB CSS (0) | — | — · — · — |
| lab/TabBar | 84.7 kB (−1 B) · 1.8 kB CSS (0) | — | — · — · — |
| AppShell | 92.1 kB (−2 B) · 14.9 kB CSS (0) | — | — · — · — |
| BaseTypeahead | 84.5 kB (−2 B) · 12.1 kB CSS (0) | — | — · — · — |
| SegmentedControl | 103.7 kB (−3 B) · 7.2 kB CSS (0) | — | — · — · — |
| SideNavHeading | 88.8 kB (−4 B) · 12.5 kB CSS (0) | — | — · — · — |
| TopNavMenu | 88.0 kB (−4 B) · 12.4 kB CSS (0) | — | — · — · — |
| DateRangeInput | 107.0 kB (−5 B) · 14.2 kB CSS (0) | — | — · — · — |
| ComplexSelector | 84.3 kB (−6 B) · 13.3 kB CSS (0) | — | — · — · — |
| Popover | 106.1 kB (−6 B) · 15.5 kB CSS (0) | — | — · — · — |
| SideNavItem | 83.1 kB (−6 B) · 12.3 kB CSS (0) | — | — · — · — |
| DateTimeInput | 234.1 kB (−7 B) · 20.7 kB CSS (0) | — | — · — · — |
| lab/ChatEmojiPicker | 129.5 kB (−7 B) · 773 B CSS (0) | — | — · — · — |
| ChatComposerInput | 88.3 kB (−11 B) · 12.5 kB CSS (0) | — | — · — · — |
| ChatComposerTokenElement | 88.3 kB (−11 B) · 12.5 kB CSS (0) | — | — · — · — |
| Dialog | 29.0 kB (−11 B) · 7.3 kB CSS (0) | — | — · — · — |
| lab/ChatReactionBar | 130.6 kB (−12 B) · 1.1 kB CSS (0) | — | — · — · — |
Package size: @astryxdesign/core 8.00 MB packed (+2.2 kB); no new dependencies.
Touched components checked; for the full suites, add ci:run-visual for Visual, ci:run-rtl for RTL.
Generated by PR Enrichment workflow | View full report
Keep replacement focus within its original owner, expire stale Activity handoffs, and forward non-HTML refs without treating them as focus targets. Consolidate regression tests, avoid parameterized cases, and retain only necessary comments.
There was a problem hiding this comment.
Changes requested: the focus fix and the disabled-callback guard work as described, but both re-implement logic the repository already shares, and each copy already behaves differently from the shared one.
NavHeadingMenuItem.tsx:172-217filters a disabled row's callbacks with its own guard instead ofwithholdCallerHandlersordisabledInteractionPropsfromutils/disabledInteraction.ts, so a disabled row still runs the caller's typing, pointer-down/up and hover callbacks that a disabledTaborSideNavItemwithholds.useFocusAcrossSwap.ts:35-95adds its own lost-focus checks (focusRoot,ownsFocus,focusIsUnclaimed) instead of callingisFocusDetachedandisFocusLost, and they already disagree with those utilities about focus on<html>and about cross-origin frames.
Next, spread withholdCallerHandlers(restProps, isDisabled) as Tab and SideNavItem do, or extend that helper and say why the row should keep hover and other-key callbacks. Route the hook's checks through the shared focus utilities, and add a shadow-root case there if you need one. CI has not run on this head yet, because it waits for a maintainer to add the ci:run label.
Claims and files checked
- Claim: focus stays on a router-link row that becomes disabled when the router does not forward refs — verified (new router test fails on the base, passes on the head).
- Claim: a disabled row no longer runs click-capture, auxiliary-click, double-click and Enter/Space callbacks in capture and bubble phases — verified (new pointer and keyboard tests, red on the base).
- Claim: other keys, focus and hover observation, parent menu events and label content events keep running — verified (
NavHeadingMenuItem.test.tsx:237-238,:289, child-event test). - Claim: disabled navigation, tab order and menu keyboard movement are unchanged — verified (
NavHeadingMenu.test.tsx, 46 tests, passes on the head). - Claim: the old focus tracking sat on the forwarded row ref — verified (base
NavHeadingMenuItem.tsx). - Claim: the shared focus hook now attaches to the row's content span and finds the row from there — verified (
NavHeadingMenuItem.tsx:168-170,:231). - Claim: focus is restored only while it is unclaimed, and hidden Activity content keeps no stale handoff — verified (
useFocusAcrossSwap.ts:125-133,:111; hook tests). - Claim: existing direct-ref users of the hook are unchanged, and non-element refs are forwarded but never focused — verified (
Item.tsx:677,TreeListItem.tsx:434; hook test). - Claim: disabled destinations stay absent, rows keep
tabIndex=-1, and arrows and typeahead reach disabled rows — verified (NavHeadingMenuItem.tsx:196-198; existing tests). - Claim: no Link implementation, public prop, role policy, styling or layout change — verified (API surface comparison shows no change).
- Claim: the focused suites pass (9 files, 310 tests), and ESLint and Prettier are clean — verified (rerun on the head).
- Claim: repository-wide checks and the whitespace check pass — whitespace verified; the repository-wide checks were not re-verified.
- Claim: public text has no internal context — verified.
- File
.changeset/ast-085-nav-heading-menu-item.md— clear (valid changeset; text matches the code). - File
apps/storybook/stories/NavMenu.stories.tsx— clear. - File
packages/core/src/NavMenu/NavHeadingMenuItem.tsx— finding 1. - File
packages/core/src/NavMenu/NavHeadingMenuItem.test.tsx— finding 1 (asserts typing and hover callbacks on a disabled row). - File
packages/core/src/utils/useFocusAcrossSwap.ts— finding 2. - File
packages/core/src/utils/useFocusAcrossSwap.test.tsx— clear.
There was a problem hiding this comment.
This needs an engineering owner's decision before it can be approved, and one required fix.
Owner decision: the shared isFocusLost in packages/core/src/utils/focusReturn.ts now treats focus as never lost in a cross-origin child document that does not have focus. That stops focus theft when the embedding page holds focus, but it also means that in an embedded app a focus trap (Dialog, Drawer, Popover), the removal repair, ComplexSelector or a disclosure that closes while the browser window is in the background no longer gets the shared focus return, so focus can stay on the body where it was returned before. The overlay-dismissal record returns focus "when it would otherwise be lost" and does not settle this case. An engineering owner records the decision by commenting /approve-spec <full head SHA> on this pull request (the author may do so if they are an engineering owner), or asks to keep the previous behavior there.
Required fix:
- Regression: the changeset and the description still say a disabled row keeps other-key and hover callbacks, but
NavHeadingMenuItem.tsx:174now withholds every caller callback exceptonFocusandonBlur, as the new tests assert (NavHeadingMenuItem.test.tsx:249-251,:301-302); please reword both and update the evidence and test counts to this revision.
The row fix itself works: in Chromium, focus now stays on a destination that becomes unavailable under a router that drops ref, and the disabled row runs no caller callback. CI has not run on this head yet; a maintainer adds the ci:run label so it runs.
Claims and files checked
- Claim: focus stays on a router-link row that becomes disabled when the router does not forward refs — verified (new router tests fail on the base and pass here; real-browser before/after).
- Claim: a disabled action row no longer runs click-capture, auxiliary-click, double-click and Enter/Space callbacks — verified (it now withholds every caller callback except focus and blur).
- Claim: other keys and hover callbacks keep running on a disabled row — false (
NavHeadingMenuItem.test.tsx:249-251,:301-302). - Claim: parent menu events, focus callbacks and caller-rendered label events keep running — verified (keyboard and child-event tests).
- Claim: disabled navigation, tab order and menu keyboard movement are unchanged — verified (
NavHeadingMenu.test.tsx, 46 tests). - Claim: the focus hook attaches to the row's own content and finds the row from there — verified (
NavHeadingMenuItem.tsx:168-170,:201). - Claim: focus is restored only while it is unclaimed, and hidden Activity content keeps no stale handoff — verified (
useFocusAcrossSwap.ts:79-88; hook tests). - Claim: existing direct-ref users of the hook are unchanged, and non-element refs are forwarded but never focused — verified (
Item.tsx:677,TreeListItem.tsx:434; hook test). - Claim: disabled destinations stay absent, rows keep
tabIndex=-1, and arrows and typeahead reach disabled rows — verified. - Claim: no Link implementation, public prop, role policy, styling or layout change — verified (API surface comparison shows no change).
- Claim: the before/after recordings and the real-browser comparison — they describe the previous revision; the same before/after results reproduce on this head in Chromium.
- Claim: the focused suites pass (9 files, 310 tests) — stale: the same command runs 313 tests on this head, all passing.
- Claim: ESLint, Prettier, changeset and whitespace checks pass — verified; the other repository-wide checks were not re-run.
- Claim: public text has no internal context — verified.
- File
.changeset/ast-085-nav-heading-menu-item.md— required fix (stale claim). - File
apps/storybook/stories/NavMenu.stories.tsx— clear. - File
packages/core/src/NavMenu/NavHeadingMenuItem.tsx— clear. - File
packages/core/src/NavMenu/NavHeadingMenuItem.test.tsx— clear. - File
packages/core/src/utils/focusReturn.ts— owner decision (cross-origin rule). - File
packages/core/src/utils/focusReturn.test.ts— clear. - File
packages/core/src/utils/useFocusAcrossSwap.ts— clear. - File
packages/core/src/utils/useFocusAcrossSwap.test.tsx— clear (a nested-row Activity case would pin the cleanup Effect).
49d986e to
0fd6d8b
Compare
There was a problem hiding this comment.
Approval waits on one engineering-owner decision and one required fix.
- Owner decision: in a cross-origin iframe whose document does not have focus, a
NavHeadingMenuItem,ItemorTreeListItemrow that becomes disabled no longer gets focus back on its replacement (focusRootinpackages/core/src/utils/focusReturn.ts), whichspec:AST-085FR4 does not settle, so an engineering owner either accepts that rule by commenting/approve-spec <full head SHA>(the author may do so if they are an engineering owner) or asks for the base behavior in that state. - Required fix: the description still says the disabled-items story is updated and lists that story under Scope, but no story file changes at this head, so remove those mentions (or restore the story change) and point the Testing section at this head.
The row fix itself works: the new router tests fail before this change and pass with it, and in Chromium focus stays on a disabled row while no caller callback runs on it. CI has not run on this head yet; a maintainer adds the ci:run label so it runs.
Claims and files checked
- Claim: a router that drops its ref loses focus when the focused row becomes disabled (before) — verified by the new router tests failing before the change.
- Claim: a disabled action row still ran caller key, pointer and hover callbacks (before) — verified.
- Claim: the row attaches the shared focus hook to its own content span — verified.
- Claim: a replacement takes focus only while focus is unclaimed — verified.
- Claim: a hidden Activity does not keep a stale focus hand-off — verified, but the test fails only when both guards are removed.
- Claim: disabled rows withhold caller callbacks except focus and blur, keeping parent menu handling and caller label events — verified.
- Claim:
isFocusLostkeeps its base behavior for overlays, disclosures and removal repair — verified. - Claim: the existing direct-ref callers keep their calls, and non-element refs are forwarded but not focused — verified.
- Claim: the disabled-items story is updated (restoration list and Scope) — false; no story file changes.
- Claim: disabled destinations stay absent, rows keep
tabIndex=-1, arrows and typeahead still reach disabled rows — verified. - Claim: no public prop, role, styling or layout change — verified.
- Claim: the focused test run passes (10 files, 349 tests) — verified at this head; the description names an earlier commit.
- Claim: a removal regression keeps document-local return in an unfocused cross-origin document — verified.
- Claim: a Chromium cross-origin iframe check was run — stated by the author, not reproduced.
- Changeset: focus is preserved with routers that do not forward refs — verified.
- Changeset: disabled items withhold caller callbacks except focus and blur, keeping parent menu handling and child events — verified.
- Changeset: disabled navigation, tab order and menu keyboard movement are unchanged — verified.
- File
.changeset/ast-085-nav-heading-menu-item.md— clear. - File
packages/core/src/NavMenu/NavHeadingMenuItem.tsx— clear. - File
packages/core/src/NavMenu/NavHeadingMenuItem.test.tsx— clear. - File
packages/core/src/utils/focusReturn.ts— owner decision on the cross-origin rule. - File
packages/core/src/utils/focusReturn.test.ts— clear. - File
packages/core/src/utils/useFocusAcrossSwap.ts— clear. - File
packages/core/src/utils/useFocusAcrossSwap.test.tsx— non-blocking: the hidden-Activity test does not isolate either guard.
There was a problem hiding this comment.
Requesting changes: the disabled-row focus and callback fixes work as described, and one shared focus check needs a fix before this can merge.
- Miss:
ownsFocusandisFocusUnclaimedtreat any root with ahostproperty as a shadow root (packages/core/src/utils/focusReturn.ts:40,:49), but a document exposes namedform,iframe,img,embedandobjectelements as properties, so on a page with<form name="host">a focusedNavHeadingMenuItem,ItemorTreeListItemrow that becomes unavailable now drops focus to the page body where it used to stay (AST-085 FR4); use the sharedisShadowRootfromutils/nodeType.ts(orshadowHostOffromutils/flatTree.ts) at both sites and add a test that defineshoston the document, since jsdom has no named document properties.
Everything else checked out: the router and callback tests fail before this change and pass with it, and the unfocused cross-origin case keeps the earlier behavior.
Claims and files checked
- Verified: focus stays on a row that becomes unavailable under a router that does not forward its ref (except on a page with a named
hostelement, above). - Verified: a disabled row runs no caller callback except focus and blur, while menu-level keyboard handling and caller-rendered label content keep working.
- Verified: disabled destinations, the row's tab order and arrow and typeahead reach are unchanged.
- Verified: the hook attaches to the row's own content span and restores focus only when no other element holds it, across frames and shadow roots.
- Verified: hidden Activity content keeps no stale focus handoff, and removing the cleanup Effect fails the nested test.
- Verified:
isFocusLostis unchanged, and an unfocused child document with an unreadable parent keeps the document-local rule; re-adding the window-focus guard fails its test. - Verified: non-element refs are forwarded but never focused, and unused handoffs expire.
- Verified: no public prop, story, styling or layout change.
- Verified: the listed focused test runs (10 files, 349 tests; 5 files, 168 selected tests), the Core typecheck, and lint and formatting on the changed files; the full repository lint and build were not rerun here.
- Verified with a different count: the recording's eight keyboard callbacks come from the author's fixture; the behavior reproduces.
- Files: changeset,
NavHeadingMenuItem.tsx,NavHeadingMenuItem.test.tsx,useFocusAcrossSwap.ts,useFocusAcrossSwap.test.tsxandfocusReturn.test.tsare clear;focusReturn.tshas the finding above.
|
/approve-spec e632b8b |
There was a problem hiding this comment.
Approved pending CI: the heavy CI jobs have not run on this head yet, so the merge guard still waits for them. A focused NavHeadingMenuItem now keeps focus when it becomes unavailable under a router link that drops ref, and a disabled row runs none of the caller's event callbacks except focus and blur; a Chromium check of this patch confirms both, and each guard in the shared swap hook has a test that fails without it. One optional follow-up, already tracked in #13123:
- The restore at
useFocusAcrossSwap.tsline 86 calls plainfocus(), so after a mouse click the restored row draws the keyboard focus ring; restoring throughfocusForLastInputwould fix it for every swap caller.
Claims and files checked
Review mode: carry-forward; reason: none
- Changeset: focus is kept across disabled transitions under router links that do not forward refs: verified (
NavHeadingMenuItem.test.tsx:30,:81; Chromium keeps focus on the row where the base drops it to the page body). - Changeset: disabled items withhold caller event callbacks except focus and blur: verified (
NavHeadingMenuItem.tsx:180; tests atNavHeadingMenuItem.test.tsx:154,:213,:263; Chromium counts 16 callbacks on the base and 0 here). - Changeset: parent menu handling and caller-rendered child events are preserved: verified (
NavHeadingMenuItem.test.tsx:213,:263). - Changeset: disabled navigation, tab order and menu keyboard movement are unchanged: verified (
NavHeadingMenuItem.tsx:187-189; the NavMenu suite passes). - Description: on the base, a non-forwarding router drops focus to the page and a disabled action runs caller keyboard, pointer and hover callbacks: verified (Chromium on the base).
- Description: the item attaches the shared focus hook to its content span and finds the row from there: verified (
NavHeadingMenuItem.tsx:100-102,:174-176,:208). - Description: a replacement takes focus only while focus is unclaimed in the roots the hook can read, and hidden Activity content keeps no stale handoff: verified (
useFocusAcrossSwap.ts:78-87,focusReturn.ts:59-88; removing the Effect cleanup failsuseFocusAcrossSwap.test.tsx:238). - Description:
isFocusLostkeeps the base's document-local behavior for overlays, disclosures and removal repair: verified (unchanged atfocusReturn.ts:96-102). - Description: with an unreadable cross-origin parent, row swaps keep the document-local answer and do not reject on
hasFocus(): verified (focusReturn.ts:79-81; adding such a check failsfocusReturn.test.ts:458). - Description: both ownership checks use
isShadowRoot, so a document's namedhostelement is not taken for a shadow host: verified (focusReturn.ts:54,:63; reverting either failsfocusReturn.test.ts:422). - Description: the disabled mouse-down guard stays without reattaching the caller's handler: verified (
NavHeadingMenuItem.tsx:181-183). - Description: direct-ref callers keep their call shape, non-HTML refs are forwarded but never focused, and unconsumed handoffs expire: verified (
Item.tsx:674,TreeListItem.tsx:444andPagination.tsx:424call the hook unchanged;useFocusAcrossSwap.ts:27-34,:93-101; tests atuseFocusAcrossSwap.test.tsx:96,:276). - Description: the
focusReturn.tsheader names the ownership checks and the row-swap caller: verified (focusReturn.ts:7-17). - Description: item and shared-focus regression tests and a Core patch changeset are added: verified (file list).
- Description: disabled destinations stay absent, rows keep
tabIndex=-1, and arrows and typeahead still reach disabled rows: verified (NavHeadingMenuItem.tsx:187-189; NavMenu suite). - Description: no Link implementation, public prop, role policy, styling, layout or story change: verified (file list; the built API surface shows no change; the only other edit is two import paths).
- Description: after re-enabling, Enter navigates once and the menu closes once: verified (
NavHeadingMenuItem.test.tsx:30). - Description: the regression tests catch a removed Effect cleanup, a restored
hasFocus()check and a property-presence shadow-root check: verified (each change fails its test on this patch). - Description: the two maintainer tests each fail without the guard they cover: verified (removing the hidden-row guard fails
useFocusAcrossSwap.test.tsx:260; removing the expiry fails:276). - Description: the utils, NavHeadingMenu and Item suites, Core typecheck, ESLint and Prettier pass: consistent (617 tests across 16 files with Item, TreeList and Pagination; typecheck, lint and formatting of the changed files pass on this patch).
- Description: recordings and Chromium checks describe earlier revisions with the same functional code: consistent (Chromium on this patch shows the same focus and callback results).
- Description: a restored row receives plain
focus(), so after a mouse click it can draw the keyboard ring, and a follow-up is filed: verified (useFocusAcrossSwap.ts:86; Chromium pointer probe on this patch; #13123). - Files:
.changeset/ast-085-nav-heading-menu-item.md,NavHeadingMenuItem.tsx,NavHeadingMenuItem.test.tsx,focusReturn.ts,focusReturn.test.ts,useFocusAcrossSwap.test.tsx: each clear;useFocusAcrossSwap.ts: one non-blocking note (keyboard ring after pointer input).
|
(Posted by Cindy's agent.) Thanks @korkt-kim, this is approved and passing CI. It's waiting for two in-flight menu PRs to land first, since it touches shared menu code they depend on. After they merge, we'll bring your branch up to date with main (keeping your commits and credit), re-check it, and merge. No action needed from you. |
|
/approve-spec d55862d |
There was a problem hiding this comment.
Approved pending CI: the heavy CI jobs have not run on this head yet, so the merge guard still waits for them. A focused NavHeadingMenuItem now keeps focus when it becomes unavailable under a router link that drops ref, and a disabled row runs none of the caller's event callbacks except focus and blur; a Chromium check of this head confirms both, and each guard in the shared swap hook has a test that fails without it. One optional follow-up, already tracked in #13123:
- The restore at
useFocusAcrossSwap.tsline 86 calls plainfocus(), so after a mouse click the restored row draws the keyboard focus ring; restoring throughfocusForLastInputwould fix it for every swap caller.
Claims and files checked
Review mode: full; reason: author-not-engowner
- Changeset: focus is kept across disabled transitions under router links that do not forward refs: verified (
NavHeadingMenuItem.test.tsx:30,:81, both failing on the base; Chromium keeps focus on the row where the base drops it to the page body). - Changeset: disabled items withhold caller event callbacks except focus and blur: verified (
NavHeadingMenuItem.tsx:180; tests atNavHeadingMenuItem.test.tsx:154,:213,:263, each failing on the base; Chromium counts 14 callbacks on the base and 0 here). - Changeset: parent menu handling and caller-rendered child events are preserved: verified (
NavHeadingMenuItem.test.tsx:213,:263). - Changeset: disabled navigation, tab order and menu keyboard movement are unchanged: verified (
NavHeadingMenuItem.tsx:185-189; the NavMenu suite passes). - Description: on the base, a non-forwarding router drops focus to the page and a disabled action runs caller keyboard, pointer and hover callbacks: verified (Chromium on the base).
- Description: the item attaches the shared focus hook to its content span and finds the row from there: verified (
NavHeadingMenuItem.tsx:100-102,:174-176,:208). - Description: a replacement takes focus only while focus is unclaimed in the roots the hook can read, and hidden Activity content keeps no stale handoff: verified (
useFocusAcrossSwap.ts:78-87,focusReturn.ts:59-88; removing the Effect cleanup failsuseFocusAcrossSwap.test.tsx:238). - Description:
isFocusLostkeeps the base's document-local behavior for overlays, disclosures and removal repair: verified (unchanged atfocusReturn.ts:96-102). - Description: with an unreadable cross-origin parent, row swaps keep the document-local answer and do not reject on
hasFocus(): verified (focusReturn.ts:79-81; adding such a check failsfocusReturn.test.ts:458). - Description: both ownership checks use
isShadowRoot, so a document's namedhostelement is not taken for a shadow host: verified (focusReturn.ts:54,:63; reverting either failsfocusReturn.test.ts:422). - Description: the disabled mouse-down guard stays without reattaching the caller's handler: verified (
NavHeadingMenuItem.tsx:181-183). - Description: direct-ref callers keep their call shape, non-HTML refs are forwarded but never focused, and unconsumed handoffs expire: verified (
Item.tsx:675,TreeListItem.tsx:444andPagination.tsx:424call the hook unchanged;useFocusAcrossSwap.ts:27-34,:93-101; tests atuseFocusAcrossSwap.test.tsx:96,:276). - Description: the
focusReturn.tsheader names the ownership checks and the row-swap caller: verified (focusReturn.ts:7-17). - Description: item and shared-focus regression tests and a Core patch changeset are added: verified (file list).
- Description: disabled destinations stay absent, rows keep
tabIndex=-1, and arrows and typeahead still reach disabled rows: verified (NavHeadingMenuItem.tsx:185-189; NavMenu suite). - Description: no Link implementation, public prop, role policy, styling, layout or story change: verified (file list; the built API surface shows no change; the only other edit is two import paths).
- Description: after re-enabling, Enter on the router row navigates once and closes the menu once, and the action row runs its selection again: verified (
NavHeadingMenuItem.test.tsx:30,:154). - Description: the regression tests catch a removed Effect cleanup, a restored
hasFocus()check and a property-presence shadow-root check: verified (each change fails its test on this head). - Description: the two maintainer tests each fail without the guard they cover: verified (removing the hidden-row guard fails
useFocusAcrossSwap.test.tsx:260; removing the expiry fails:276). - Description: the named-document fix keeps focus for NavHeadingMenuItem, Item and TreeListItem rows: consistent (
focusReturn.test.ts:422and both reverts; not re-run in a browser). - Description: the utility, NavHeadingMenu and Item suites, Core typecheck, ESLint and Prettier pass: verified (1,909 tests across 83 files with TreeList and Pagination; typecheck passes; ESLint and Prettier are clean on the changed files).
- Description: recordings and Chromium checks describe earlier revisions with the same functional code: consistent (Chromium on this head shows the same focus and callback results).
- Description: a restored row receives plain
focus(), so after a mouse click it can draw the keyboard ring, and a follow-up is filed: verified (useFocusAcrossSwap.ts:86; Chromium pointer probe on this head; #13123 is open). - Files:
.changeset/ast-085-nav-heading-menu-item.md,NavHeadingMenuItem.tsx,NavHeadingMenuItem.test.tsx,focusReturn.ts,focusReturn.test.ts,useFocusAcrossSwap.test.tsx: each clear;useFocusAcrossSwap.ts: one non-blocking note (keyboard ring after pointer input).
|
/approve-spec e9f4324 |
There was a problem hiding this comment.
Approved pending CI: CI has not run on this head yet (the pull request is still a draft, so every CI job was skipped), and the merge guard waits for it. A focused NavHeadingMenuItem now keeps focus when it becomes unavailable under a router link that drops ref, and a disabled row runs none of the caller's event callbacks except focus and blur; a Chromium check of this head confirms both, and each guard in the shared swap hook has a test that fails without it. One optional follow-up, already tracked in #13123:
- The restore at
useFocusAcrossSwap.tsline 86 calls plainfocus(), so after a mouse click the restored row draws the keyboard focus ring; restoring throughfocusForLastInputwould fix it for every swap caller.
Claims and files checked
Review mode: full; reason: author-not-engowner
- Changeset: focus is kept across disabled transitions under router links that do not forward refs: verified (
NavHeadingMenuItem.test.tsx:30,:81, both failing on the base; Chromium keeps focus on the row where the base drops it to the page body). - Changeset: disabled items withhold caller event callbacks except focus and blur: verified (
NavHeadingMenuItem.tsx:180; tests atNavHeadingMenuItem.test.tsx:154,:213,:263, each failing on the base; Chromium counts 14 callbacks on the base and 0 here). - Changeset: parent menu handling and caller-rendered child events are preserved: verified (
NavHeadingMenuItem.test.tsx:213,:263). - Changeset: disabled navigation, tab order and menu keyboard movement are unchanged: verified (
NavHeadingMenuItem.tsx:185-189; the NavMenu, SideNav and TopNav suites pass). - Description: on the base, a non-forwarding router drops focus to the page and a disabled action runs caller keyboard, pointer and hover callbacks: verified (Chromium on the base).
- Description: the item attaches the shared focus hook to its content span and finds the row from there: verified (
NavHeadingMenuItem.tsx:100-102,:174-176,:208). - Description: a replacement takes focus only while focus is unclaimed in the roots the hook can read, and hidden Activity content keeps no stale handoff: verified (
useFocusAcrossSwap.ts:78-87,focusReturn.ts:59-88; removing the Effect cleanup failsuseFocusAcrossSwap.test.tsx:238). - Description:
isFocusLostkeeps the base's document-local behavior for overlays, disclosures and removal repair: verified (unchanged atfocusReturn.ts:96-102). - Description: with an unreadable cross-origin parent, row swaps keep the document-local answer and do not reject on
hasFocus(): verified (focusReturn.ts:54,:79-81; adding such a check failsfocusReturn.test.ts:458). - Description: both ownership checks use
isShadowRoot, so a document's namedhostelement is not taken for a shadow host: verified (focusReturn.ts:54,:63; reverting either failsfocusReturn.test.ts:422). - Description: the disabled mouse-down guard stays without reattaching the caller's handler: verified (
NavHeadingMenuItem.tsx:181-183). - Description: direct-ref callers keep their call shape, non-HTML refs are forwarded but never focused, and unconsumed handoffs expire: verified (
Item.tsx:675,TreeListItem.tsx:444andPagination.tsx:424call the hook unchanged;useFocusAcrossSwap.ts:27-34,:93-101; tests atuseFocusAcrossSwap.test.tsx:96,:276). - Description: the
focusReturn.tsheader names the ownership checks and the row-swap caller: verified (focusReturn.ts:7-17). - Description: item and shared-focus regression tests and a Core patch changeset are added: verified (file list).
- Description: disabled destinations stay absent, rows keep
tabIndex=-1, and arrows and typeahead still reach disabled rows: verified (NavHeadingMenuItem.tsx:187-189; NavMenu suite). - Description: no Link implementation, public prop, role policy, styling, layout or story change: verified (file list; the built API surface shows no change; the only other edit is two import paths).
- Description: after re-enabling, Enter on the router row navigates once and closes the menu once, and the action row runs its selection again: verified (
NavHeadingMenuItem.test.tsx:30,:154). - Description: the regression tests catch a removed Effect cleanup, a restored
hasFocus()check and a property-presence shadow-root check in either function: verified (each change fails its test on this head). - Description: the two maintainer tests each fail without the guard they cover: verified (removing the hidden-row guard fails
useFocusAcrossSwap.test.tsx:260; removing the expiry fails:276). - Description: the named-document fix keeps focus for NavHeadingMenuItem, Item and TreeListItem rows: consistent (
focusReturn.test.ts:422and both reverts; not re-run in a browser). - Description: the utility, NavHeadingMenu and Item suites, Core typecheck, ESLint, Prettier and the full build pass: verified (2,572 tests across 93 files with SideNav, TopNav, TreeList and Pagination; typecheck, ESLint and Prettier clean; the root build passes).
- Description: recordings and Chromium checks describe earlier revisions with the same functional code: consistent (Chromium on this head shows the same focus and callback results).
- Description: a restored row receives plain
focus(), so after a mouse click it can draw the keyboard ring, and a follow-up is filed: verified (useFocusAcrossSwap.ts:86; Chromium pointer probe on this head; #13123 is open). - Files:
.changeset/ast-085-nav-heading-menu-item.md,NavHeadingMenuItem.tsx,NavHeadingMenuItem.test.tsx,focusReturn.ts,focusReturn.test.ts,useFocusAcrossSwap.test.tsx: each clear;useFocusAcrossSwap.ts: one non-blocking note (keyboard ring after pointer input).
|
🤖 (Posted by Cindy's agent.) Merged, thank you @korkt-kim, and thanks for your patience while the shared menu work landed first! In a NavHeadingMenu, a disabled row now keeps focus so keyboard users can still reach and read it, but it can't be activated. A small follow-up, #13123, will make a restored row skip the keyboard focus ring after a mouse click. It ships in the next release, with you credited. |
User impact
A person can be focused on a nav-heading menu destination when it becomes unavailable. With a
LinkProviderrouter that does not forward a DOM ref, that transition drops focus to the page. A disabled action row also still invokes consumer keyboard, pointer, and hover callbacks, even though its selection callback is blocked. Those callbacks can change application state while the row is unavailable.Problem and solution fit
Focus tracking is attached to the router's forwarded ref, which the router may not provide. The item now attaches the existing shared focus owner to its own content span and resolves the focusable row from there. It restores a focused immediate replacement only while focus remains unclaimed in the roots it can inspect. Hidden Activity lifetimes do not retain a stale focus handoff.
The item uses
withholdCallerHandlersto withhold caller event callbacks except focus and blur while disabled. Parent menu handling and caller-owned label events keep their existing paths.The shared
focusReturnmodule supplies exact-ownership and unclaimed-focus checks for row replacements. Its existingisFocusLostfunction retains the PR base's document-local behavior for overlays, disclosures, and removal repair. Row replacements check accessible enclosing frames and shadow hosts. When a cross-origin parent cannot be inspected, they retain the document-local fallback rather than rejecting restoration solely becauseDocument.hasFocus()is false. Both ownership checks use the sharedisShadowRootguard, so a document's namedhostelement is not mistaken for a shadow host.Expected behavior and authority
Smallest restoration
useFocusAcrossSwapfor an owned-content attachment while retaining its existing direct-ref call sites. Non-HTML refs are still forwarded, but are not inspected as focus targets. Expire unconsumed focus handoffs and keep the item's FR4 claim lookup intact.focusReturn, separate from the existing document-localisFocusLostcontract. The file header names those checks and the row-swap caller.Disabled destinations remain absent, rows retain
tabIndex=-1, and arrows/typeahead still reach disabled rows. No Link implementation, public prop, role policy, production styling, production layout, or story change is included.Evidence
hasFocus()returning false; it detects the removed guard. The removal regression still protects overlay return, and the frame and shadow-root cases protect inspectable caller handoffs. A named-document regression detects either ownership check reverting to property-presence detection.The linked recordings use Playwright Chromium 149 at 1280 × 800 with the same fixture and input sequence. The fixture loads the base item and focus-hook modules from
24abd1dfa4for AS-IS and the implementation ate91f185239for TO-BE. They document that earlier revision's original correction, not the later shared-helper follow-ups. F8/F9 change availability without taking focus. Readouts come from real DOM focus and callbacks; the temporary fixture and media are not part of the source diff. These clips cover Chromium light-DOM behavior, not screen-reader speech or cross-browser conformance.Chromium 156 checks at
6353c47094confirm focus retention for the non-forwarding router, blocked disabled keyboard and pointer callbacks, re-enabled navigation, arrow movement, focused same-origin and cross-origin row replacements, and caller-selected local input and shadow-host handoffs. A fresh named-document comparison reproduces all three shared-hook callers dropping focus on that revision when<form name="host">is present; removing the named form removes the failure. With this correction, NavHeadingMenuItem, Item, and TreeListItem retain focus on disable and re-enable, including inside a same-origin iframe. Separate checks cover native namedform,iframe,img,embed, andobjectelements, preserve an outside input's focus, and retain the existing shadow-host fallback. The background-window condition remains modeled by the DOM regression, not claimed as a real-browser background-window reproduction.AS-IS
nav-heading-disabled-as-is.mp4
TO-BE
nav-heading-disabled-to-be-e91f185239.mp4
Scope
Components: NavHeadingMenuItem, internal useFocusAcrossSwap and focusReturn
Follow-up: #13123. A restored row receives plain
focus(), so after a mouse click it can draw the keyboard focus ring (as native-link rows already do onmain); restoring through the shared last-input focus helper fixes every caller of this hook.Testing
For the test-only maintainer commit
ec8c483dbd: two cases inuseFocusAcrossSwap.test.tsx, each failing with its guard removed. A row that Suspense hides and returns replaced in the same task does not take focus (fails without the hidden-ancestor check). A handoff from a descendant ref that detaches while the hook's Effect stays connected expires before a later replacement (fails without the microtask expiry). utils, NavHeadingMenu and Item suites: 75 files, 1,506 tests pass; coretsc, eslint and Prettier are clean.For the header-only follow-up
c4f5be7fea:pnpm exec vitest run --project ui packages/core/src/utils/focusReturn.test.ts packages/core/src/utils/useFocusAcrossSwap.test.tsx --maxWorkers=2— 2 files, 44 tests passed.lint-stagedandpnpm check:repo— passed.pnpm specs:for --diff origin/main,pnpm review:pre, andgit diff --check— completed; the pre-review report lists no automatic findings.The functional implementation is unchanged. Earlier checks for
773416324e, including the named-document correction:pnpm exec vitest run --project ui packages/core/src/NavMenu packages/core/src/utils/useFocusAcrossSwap.test.tsx packages/core/src/utils/focusReturn.test.ts packages/core/src/Item packages/core/src/TreeList packages/core/src/utils/nodeType.test.ts packages/core/src/utils/flatTree.test.ts packages/core/src/gestures/__tests__/touchActionRule.test.ts --maxWorkers=2— 13 files, 365 tests passed.pnpm exec vitest run --project ui packages/core/src/hooks/useFocusTrap.test.tsx packages/core/src/ComplexSelector/ComplexSelector.test.tsx packages/core/src/Layer/useLayer.test.tsx packages/core/src/Dialog/Dialog.test.tsx packages/core/src/BottomSheet/BottomSheet.test.tsx --testNamePattern 'focus|Focus|iframe|shadow|remov|unmount' --maxWorkers=2— 5 files, 168 selected tests passed; 372 skipped by the name filter.pnpm exec vitest run --project ui packages/core/src/utils --maxWorkers=2— 68 files, 1,243 tests passed; this overlaps the focused utility tests above.pnpm -F @astryxdesign/core typecheck— Core source, tests, and consumer docs passed.pnpm lint:strict— passed with 0 errors and 237 warnings; includes repository, knowledge, and changeset validation.pnpm build— full package build passed.lint-stagedandpnpm check:repo— passed without changing the validated source.pnpm specs:for --diff origin/main,pnpm review:pre, andgit diff --check— completed; the pre-review report lists no automatic findings.