Skip to content

fix(Comments): Mark as resolved and Reopen hand focus to the control that replaces them - #13737

Open
ernestt wants to merge 1 commit into
fix/comments-selected-focus-ringfrom
fix/comments-resolve-focus
Open

ernestt wants to merge 1 commit into
fix/comments-selected-focus-ringfrom
fix/comments-resolve-focus

Conversation

@ernestt

@ernestt ernestt commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #13736 (the previous Comments fix) only so the Comments move includes it. It touches none of CommentPin's files and applies cleanly to main (2608fe4) on its own.

User impact

A keyboard user who presses Mark as resolved, or Reopen, loses focus to the page body. Resolving replaces Mark as resolved with Reopen, and reopening does the reverse, when the host's update arrives. The pressed control leaves the page, and focus goes with it. The user must tab from the top of the page back to the thread.

Problem and solution fit

  1. Why does focus drop? The pressed button unmounts when the host flips isResolved, and nothing moves focus to the control that replaces it.

  2. Why does it harm the task? Resolve and reopen are the last step of reviewing a thread. Losing focus after them breaks the keyboard path through the panel, and a screen reader announces nothing useful.

  3. Why does it matter? The Comments docs promise "Focus never drops to the page", and every other action in the panel keeps it.

  4. Why could Core's hand-off not serve as it stood? OverflowList renders each action twice: an inert copy to measure it, then the visible one. Both copies take the same ref, and the copy's ref detaches and attaches first, so it cleared or took the hook's hand-off before the visible replacement mounted.

  5. Why did focus still drop in a narrow panel? In a panel 480 CSS px wide or narrower, Reopen is too wide for the actions row. It takes focus, then OverflowList collapses it into the more menu, and no element with the hand-off ref replaces it.

Mark as resolved and Reopen now take one ref from Core's focus hand-off, useFocusAcrossSwap, which Item, Pagination, Token, TreeList and NavMenu headings already use when React replaces a focused element. When the pressed control leaves the page while it has focus, the control that replaces it takes focus. If the viewer has moved focus elsewhere by the time the host's update arrives, focus stays where they put it. A failed request replaces nothing, so focus does not move. While Mark as resolved or Reopen sits in the more menu, the menu's trigger takes the same ref, so a pressed control that collapses there gives focus to the trigger, the destination Add reaction already uses when it is not in the row. The hook now ignores an element while it is inside an inert region, and it reads inertness each time it records or takes a hand-off, not once when the element attaches.

Expected behavior and authority

  • spec:AST-085 FR4 (when a component removes a focused control, the component names where focus goes): for Mark as resolved and Reopen, it is the control that replaces it, or the more-menu trigger when that control sits in the more menu. Comments has no record in Lab; the draft record that comes with its move to Core names this destination.
  • The Comments docs (Accessibility, "Focus after changes"): "Focus never drops to the page."
  • WCAG 2.4.3 Focus Order.
  • Component audit rubric BLOCK A5 (graduation issue list): focus is lost after resolve and reopen. It was confirmed open on main in Chromium before this change: after Enter on Mark as resolved, and after Enter on Reopen, the active element is the body. The other half of that BLOCK, native-disabled buttons, is already fixed on main, since Core Button uses aria-disabled.

Smallest restoration

  • Comments' Mark as resolved and Reopen controls share one useFocusAcrossSwap ref. Comments keeps no focus state for this hand-off. main removed the action slots, so the ref sits on the IconButton and Button that are OverflowList's direct children.
  • While the resolve action sits in the more menu, the more-menu trigger takes the same ref, through DropdownMenu's button.ref, so a control that collapses into the menu after it takes focus gives focus to the trigger.
  • useFocusAcrossSwap ignores an element while it is inside an inert region, such as OverflowList's measuring copy: that element neither records a hand-off nor takes one. The hook reads inertness when it records a hand-off and when it takes one, not when the element attaches, so a control first mounted inside an inert region, such as a link row in a covered BottomSheet, keeps its hand-off once the region is live again. An element in an inert region can hold no focus, so Core's other callers see no change.
  • Core's internal @astryxdesign/core/internal/touch entry re-exports the hook for Astryx's own packages, beside the focus helpers it already carries for Lab (isFocusLost, focusForLastInput). It is outside the public API (spec:AST-017 FR21). A [chore] Internal: changeset names it.

No public API, visual, or other behavior change.

Evidence

  • Reproduction before the change: Lab/Comments panel story in real Chromium. Focus the visible Mark as resolved on the "plan" thread, press Enter: the active element is the body. Then Reopen, Enter: the body again.
  • Result after the change, repeated on this head in real Chromium on the same story, where OverflowList renders its inert measuring copy: after Enter on Mark as resolved, focus is on Reopen, with the focus ring. After Enter on Reopen, focus is on Mark as resolved.
  • Narrow panels, on this head in real Chromium, with the Panel story's container set to each width: at 420 and 480 CSS px, Reopen collapses into the more menu and focus lands on the menu's trigger ("Actions for Maya Chen's comment"), with the focus ring; at 560 and 920 px, focus lands on Reopen. Choosing Reopen from that menu at 420 px leaves focus on the trigger. Before this head, focus fell to the page body at 420 and 480 px.
  • Wide panel round trip, on this head in real Chromium at 920 px: Enter on Mark as resolved puts focus on Reopen, and Enter on Reopen puts it on Mark as resolved.
  • Representative unchanged path: a host that resolves the thread after the viewer moved focus elsewhere leaves focus where the viewer moved it (test).
  • Regression tests: in Comments.test.tsx, "hands focus to Reopen after a keyboard resolve, and back after Reopen", which fails without the fix, and "leaves focus where the viewer moved it when the host resolves later"; in useFocusAcrossSwap.test.tsx, "carries focus to the visible replacement past an inert copy of the element", which fails without the inert skip, and "keeps the handoff for a control first mounted inside an inert region", which fails when inertness is read only when the element attaches; and in Comments.test.tsx, "hands focus to the more-menu trigger when Reopen collapses into the menu after a keyboard resolve", which fails without the trigger's ref.

The captures below come from the first version of this fix, which kept its own hand-off in Comments. This head gives the same result in the same story (the re-run above).

Before: after Enter on Mark as resolved (focus on the page body) After: focus on Reopen
Before After
Before: after Enter on Reopen (focus on the page body) After: focus on Mark as resolved
Before After

Scope

Components: Comments, CommentThread.

Core files: packages/core/src/utils/useFocusAcrossSwap.ts and useFocusAcrossSwap.test.tsx, packages/core/src/internal/touch.ts and touch.test.ts, scripts/touch-support-bundle.test.mjs, and the changeset .changeset/comments-resolve-focus-handoff.md.

  • 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

  • Repeated on this head. vitest run packages/lab/src/Comments packages/core/src/utils/useFocusAcrossSwap.test.tsx packages/core/src/internal/touch.test.ts scripts/touch-support-bundle.test.mjs: 139 passed. The two Comments keyboard tests and the hook's two inert tests fail without the fix.

  • tsc --noEmit for @astryxdesign/core and @astryxdesign/lab: pass. ASTRYX_STRICT_LINT=1 eslint and prettier --check on the changed files: clean.

  • pnpm review:pre: 0 findings. node scripts/check-changesets.mjs: valid.

  • Real Chromium (Playwright) on a static Storybook build of this head, scoped to #storybook-root, reading document.activeElement after each Enter, at 420, 480, 560 and 920 px panel widths.

  • Rebased onto main at 2608fe4, with the pull requests below this one. main had changed useFocusAcrossSwap.ts (a shorter header and focusTargetWithin) and removed CommentActionSlot; the hook's header keeps main's text plus one sentence on inert regions, and the helper is renamed isInInertRegion, as that sentence now says.

@vercel

vercel Bot commented Nov 24, 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 Dec 2, 2026 5:15am UTC

Request Review

@astracat-bot

astracat-bot Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Dec 2, 2026, 5:32 AM UTC

@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.

Changes requested: the resolve and reopen focus handoff reads correctly, but it adds a second copy of focus logic that Core already shares.

  • claimResolveFocus (CommentsContext.tsx:347-385) re-implements Core's focus-lost test (isFocusLost, which Lab already imports from @astryxdesign/core/internal/touch) and the replacement handoff that useFocusAcrossSwap owns, so call isFocusLost(null, element.ownerDocument) instead of the inline test and carry the swap through useFocusAcrossSwap (exported for Lab and taught to skip OverflowList's inert measuring copy), or explain in the description why the shared hook cannot serve this case.

Optional: the tests' OverflowList mock renders no inert measuring copy, so the [inert] skip at CommentsContext.tsx:354 is not covered by a test.

Claims and files checked

Review mode: full; reason: no-earlier-review

  • Claim, the change touches only Comments files and none of CommentPin's: verified, four files under packages/lab/src/Comments/.
  • Claim, it applies cleanly to main: verified, the commit merges onto the current main without conflict.
  • Claim, on the base focus falls to the page after Mark as resolved or Reopen: verified by code, the two buttons swap under different keys and the base resolve and reopen have no focus step.
  • Claim, the Comments docs promise focus never drops to the page: verified, Comments.doc.mjs:156.
  • Claim, the panel's other control swaps keep focus: verified for reply, edit, delete, history, the reaction picker and Load earlier comments.
  • Claim, a press records the control it waits for: verified, CommentsContext.tsx:371-377.
  • Claim, the replacement takes focus only when focus fell to the page, and focus moved elsewhere stays: verified by code, CommentsContext.tsx:359-365.
  • Claim, a failed request records nothing: verified in effect, the record is cleared on failure at CommentsContext.tsx:378-384.
  • Claim, the inert measuring copy is skipped: verified by code at CommentsContext.tsx:354; no test covers it.
  • Claim, no API, visual or other behavior change: verified, only internal Comments types change and no style changes.
  • Claim, Core Button uses aria-disabled: verified in Button.tsx.
  • Claim, the new keyboard test fails without the fix: not run here; consistent with the code.
  • Claim, the listed test, lint and browser runs pass: not reproduced here.
  • Claim, the branch sits on the stated main commit: verified.
  • File CommentsContext.tsx: the shared-path finding above.
  • File CommentRow.tsx: clear.
  • File CommentActions.tsx: clear.
  • File Comments.test.tsx: clear; the optional coverage note above.

Automated review (maintainer link)

@ernestt
ernestt force-pushed the fix/comments-resolve-focus branch from a72ff8b to f90cbbd Compare November 24, 2026 18:45
@ernestt

ernestt commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Reworked to reuse Core's hand-off. Mark as resolved and Reopen now share one useFocusAcrossSwap ref, and Comments keeps no focus state of its own: resolveFocusRef, claimResolveFocus and runResolveAction are gone. The hook decides whether focus is free with isFocusUnclaimed, which reads isFocusLost.

  • The hook skips an inert copy, such as OverflowList's measuring row, so that copy neither records nor takes the hand-off.
  • Core's internal touch entry re-exports the hook for Lab, with a [chore] Internal: changeset.
  • New hook test, "carries focus to the visible replacement past an inert copy of the element", fails without the skip. It also covers the [inert] case the Comments mock left out.
  • Real Chromium on this branch's Storybook, with the real OverflowList: focus lands on Reopen after Mark as resolved, and on Mark as resolved after Reopen.

@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.

Changes requested: the Comments fix now reuses Core's focus hand-off as asked, but the hook's new inert check regresses focus for some Core controls, and the description no longer matches the code.

  • useFocusAcrossSwap decides the inert skip once, when a node attaches (useFocusAcrossSwap.ts:80-85), so a Core control first mounted inside an inert region, such as a link Item row or a Pagination link in a covered BottomSheet, drops focus to the page when it is later disabled or swapped while focused; please read inertness when the hand-off is taken and when it is recorded, and add a test that mounts under inert, removes it, focuses the control and swaps it.
  • The description's "Problem and solution fit" and "Smallest restoration" still describe the earlier CommentsContext and claimResolveFocus implementation, so please rewrite them to the Core hook, its inert skip and the internal re-export (your latest comment already says this), list the Core files under Scope, and say that the Testing and Evidence runs were repeated on this head.

Non-blocking: the new comment in CommentRow.tsx reads better as two sentences (see the inline note).

Claims and files checked

Review mode: full; reason: author-not-engowner

  • Changeset, the hand-off skips an inert copy: verified (useFocusAcrossSwap.ts:80-85, useFocusAcrossSwap.test.tsx:295-302).
  • Changeset, the internal entry re-exports the hook: verified (touch.ts:133, touch.test.ts:213-219).
  • Changeset, Comments carries focus from Mark as resolved to Reopen and back: verified (CommentRow.tsx:383-400, Comments.test.tsx:1229).
  • Changeset, not part of the public API: verified (internal subpath only).
  • Changeset, apps see no change: false for a control first mounted inside an inert region.
  • Description, stacked on #13736 and touching no CommentPin files: verified.
  • Description, applies cleanly to main: verified.
  • Description, focus fell to the page body before the change: verified from the base code.
  • Description, a press records which control it waits for: false.
  • Description, CommentsContext keeps the intent and offers claimResolveFocus, which skips the inert copy: false.
  • Description, the controls take a ref that calls it: false as worded; they take Core's hook ref.
  • Description, focus is taken only when it has fallen to the page, and moved focus stays: verified (Comments.test.tsx:1270).
  • Description, a failed request records nothing: true in effect, but it describes the removed mechanism.
  • Description, no API or visual change: verified.
  • Description, the regression tests exist and the first fails without the fix: the tests exist; the failure is consistent with the base code but was not run here.
  • Description, test, lint and real-browser results: not re-run in this review.
  • Files: the changeset (finding), useFocusAcrossSwap.ts (finding), useFocusAcrossSwap.test.tsx (clear, but no inert-then-live test), touch.ts (clear), touch.test.ts (clear), scripts/touch-support-bundle.test.mjs (clear), CommentActions.tsx (clear), CommentRow.tsx (non-blocking comment note), Comments.test.tsx (clear).

Automated review (maintainer link)

@ernestt
ernestt force-pushed the fix/comments-selected-focus-ring branch from 40e589a to a9f094d Compare November 24, 2026 22:28
@ernestt
ernestt force-pushed the fix/comments-resolve-focus branch from f90cbbd to ee9ee12 Compare November 24, 2026 22:28
@ernestt

ernestt commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

The hook now reads inertness when it records a hand-off and when it takes one, not when the element attaches. A control first mounted inside an inert region, such as a link row in a covered BottomSheet, keeps its hand-off once the region is live again. OverflowList's measuring copy is still ignored.

  • New test, "keeps the handoff for a control first mounted inside an inert region": it mounts the control under inert, removes inert, focuses the control and swaps it. It fails with the attach-time check.
  • The CommentRow comment is now two sentences.
  • The description now covers the Core hook, lists the Core files under Scope, and says Testing and Evidence were repeated on this head: 138 tests pass, and in real Chromium focus lands on Reopen, then on Mark as resolved.

@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.

Approved pending CI: CI has not run on this head yet. Mark as resolved and Reopen now hand focus to the control that replaces them through Core's shared useFocusAcrossSwap, and the hook reads inertness when it records or takes a hand-off, so the earlier focus regression for controls first mounted inside an inert region is gone and the description now matches the code.

Non-blocking: the grown header in useFocusAcrossSwap.ts can be one line shorter and in active voice (see the inline note).

Claims and files checked

Review mode: full; reason: author-not-engowner

  • Changeset, the hand-off ignores an element inside an inert region: verified (useFocusAcrossSwap.ts:83, :99; tests at useFocusAcrossSwap.test.tsx:295 and :304).
  • Changeset, the internal touch entry re-exports the hook for Astryx's own packages: verified (touch.ts:133, touch.test.ts:213, the bundle guard's Lab-only list).
  • Changeset, Comments carries focus from Mark as resolved to Reopen and back: verified (CommentRow.tsx:383-401, Comments.test.tsx:1229).
  • Changeset, not public API, and apps see no change: verified (internal subpath only; Core callers each run their own hand-off, and an inert element cannot hold focus).
  • Description, focus fell to the page body before the change: verified from the base code.
  • Description, the overflow list's inert measuring copy took or cleared the hand-off first: verified (OverflowList.tsx:407-419).
  • Description, focus the viewer moved elsewhere stays, and a failed request moves nothing: verified (Comments.test.tsx:1270; nothing is swapped without the host's update).
  • Description, inertness is read at record and take, so a control first mounted in an inert region keeps its hand-off: verified (useFocusAcrossSwap.ts:83, :99, test at :304).
  • Description, the hook already serves Item, Pagination, Token, TreeList and NavMenu headings: verified.
  • Description, the internal entry already carries the focus-lost and last-input helpers for Lab: verified (touch.ts:100-101).
  • Description, Core Button already uses aria-disabled: verified (Button.tsx:1111).
  • Description, Comments has no record yet, and a later record names the destination: the first half is verified; the second refers to a later pull request.
  • Description, stacked on the previous Comments fix, touching no CommentPin file, and applying cleanly to main: verified.
  • Description, the regression tests exist and fail without the fix: the tests exist, and the failures follow from the base code; not run here.
  • Description, test, typecheck, lint, pre-review and real-browser results: not re-run in this review.
  • Files: the changeset (clear), touch.ts (clear), touch.test.ts (clear), useFocusAcrossSwap.ts (non-blocking header note), useFocusAcrossSwap.test.tsx (clear), CommentActions.tsx (clear), CommentRow.tsx (clear), Comments.test.tsx (clear), scripts/touch-support-bundle.test.mjs (clear).

Automated review (maintainer link)

@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.

Changes requested: in wide panels, Mark as resolved and Reopen now hand focus to the control that replaces them, but three claims in the title, description and changeset do not hold at this head.

  • Newly live check: in a Comments panel 480 CSS px wide or narrower, Reopen collapses into the more menu right after it takes focus, so focus still falls to the page body after Mark as resolved (reproduced locally at 420 and 480 px, while 560 px and wider keep focus on Reopen); send focus to the more-menu trigger when the focused resolve control collapses, as Add reaction already does, with a test at such a width, or narrow the title, description and changeset.
  • Regression: the description says the change applies cleanly to main, but main has since changed useFocusAcrossSwap.ts and removed CommentActionSlot from CommentActions.tsx, so both files now conflict; rebase through the stack and put the ref on main's direct IconButton and Button children, or correct the sentence.
  • Newly live check: "Comments keeps no focus state of its own" is false, because CommentRow.tsx, CommentsContext.tsx and CommentComposer.tsx each keep focus state; say "no focus state for this hand-off" instead.

The wide-panel fix checks out in a local run: the new tests fail on the base and pass on this head, and a real browser moves focus to Reopen and back. The earlier non-blocking note on the hook's file header still applies.

Claims and files checked

Review mode: full; reason: recipe-changed (many rules)

  • Title (live): "fix(Comments): Mark as resolved and Reopen hand focus to the control that replaces them": false for panels 480 CSS px wide or narrower (first finding); verified for wider panels (the keyboard hand-off test, and a local real-browser run).
  • Stacked on the previous Comments fix and touches no CommentPin file: verified (the changed-file list).
  • Applies cleanly to main: false at current main (second finding).
  • On the base, a keyboard user loses focus to the page body after resolve or reopen: reported; reproduced locally on the base.
  • The pressed button unmounts when the host flips the resolved state, and nothing moves focus: verified (base code; the new Comments test fails on the base).
  • The Comments docs promise focus never drops to the page: verified (Comments.doc.mjs:156).
  • Every other action in the panel keeps focus: reported (a statement about the base).
  • The overflow list renders an inert measuring copy first and the visible one second, both taking the same ref: verified (OverflowList.tsx:407-421; a local browser probe finds both copies; the hook's inert-copy test fails on the base).
  • Item, Pagination, Token, TreeList and NavMenu headings already use the hook: verified (a repository-wide search finds exactly these five callers).
  • The replacement takes focus when the pressed control leaves with focus: false for narrow panels (first finding); verified for wide panels.
  • Focus the viewer moved elsewhere stays there: verified (Comments.test.tsx:1270, passing locally).
  • A failed request moves nothing: verified (a local check with a rejecting host keeps focus on the same Mark as resolved button).
  • The hook ignores an element inside an inert region and reads inertness when it records or takes a hand-off: verified (useFocusAcrossSwap.ts:83, :99; tests at useFocusAcrossSwap.test.tsx:295 and :304; an attach-time variant fails the second test locally).
  • The focusable-disabled record's removal clause names where focus goes: verified (paraphrase of the current clause).
  • Comments has no record yet: verified; a later draft record naming the destination: unverified (no such pull request is open), and not a claim about this code.
  • Core Button already uses aria-disabled: verified (Button.tsx:1111).
  • Mark as resolved and Reopen share one hook ref: verified (CommentRow.tsx:383-401); Comments keeps no focus state of its own: false (third finding).
  • A control first mounted inside an inert region keeps its hand-off: verified (test at useFocusAcrossSwap.test.tsx:304).
  • Core's other callers see no change: verified (each of the five callers drives one element per hook instance, so an inert copy only drives its own instance, whose element cannot hold focus).
  • The internal touch entry re-exports the hook beside the focus helpers it already carries for Lab: verified (touch.ts:100-101, :133; touch.test.ts:213).
  • Outside the public API, with an internal changeset: verified (the internal subpath rule; a local surface comparison lists no public change; the bundle guard).
  • No public API, visual or other behavior change: verified, bounded by the diff and the hook's direct importers.
  • Real-browser before and after results: reported; reproduced locally.
  • The new tests fail without the fix: reported; confirmed locally (the Comments and inert-copy tests fail on the base; the inert-region test fails against an attach-time check).
  • 138 tests pass: verified (local run, 138 passed).
  • Typecheck, ESLint, Prettier and the changeset check pass: reported; re-run locally and passing; the pre-review checklist: reported.
  • Validated on an earlier main: reported.
  • Changeset, the hand-off ignores inert regions: verified; the internal entry re-exports it: verified; Comments carries focus from Mark as resolved to Reopen and back: false for narrow panels (first finding); not public API and apps see no change: verified.
  • Files: the changeset (first finding), touch.ts (clear), touch.test.ts (clear), useFocusAcrossSwap.ts (conflicts with current main; non-blocking header note), useFocusAcrossSwap.test.tsx (clear), CommentActions.tsx (first and second findings), CommentRow.tsx (first finding), Comments.test.tsx (its overflow mock never collapses, so it misses the first finding's case), scripts/touch-support-bundle.test.mjs (clear).

Automated review (maintainer link)

…that replaces them

Resolving a thread replaces Mark as resolved with Reopen, and reopening it
replaces Reopen with Mark as resolved, when the host's update arrives. The
pressed control left the page, so keyboard focus fell to the page body. Both
controls now take one ref from Core's focus hand-off, useFocusAcrossSwap:
when the pressed control leaves while it has focus, the control that
replaces it takes focus, unless focus has moved somewhere else. A failed
request replaces nothing.

OverflowList renders an inert copy of each action to measure it, so the
hand-off ignores an element while it is inside an inert region. It reads
inertness when it records or takes a hand-off, not when the element
attaches, because a region can stop being inert later. Core's internal
entry re-exports the hook for Lab.

In a narrow panel, Reopen does not fit the actions row and collapses into
the more menu right after it takes focus. While the resolve action sits in
that menu, the menu's trigger takes the same ref, so focus moves to the
trigger.
@ernestt

ernestt commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

All three points are fixed, on main at 2608fe4:

  • Narrow panels. While Mark as resolved or Reopen sits in the more menu, the menu's trigger takes the same hand-off ref, through DropdownMenu's button.ref. When Reopen takes focus and then collapses into the menu, focus moves to the trigger, the destination Add reaction already uses.
    • New test, "hands focus to the more-menu trigger when Reopen collapses into the menu after a keyboard resolve": the OverflowList mock collapses Reopen. It fails without the trigger's ref.
    • Real Chromium on a Storybook build of this head, with the Panel story's container at each width: at 420 and 480 px, focus lands on "Actions for Maya Chen's comment", with the focus ring. At 560 and 920 px, focus lands on Reopen, and Enter on Reopen returns it to Mark as resolved. Choosing Reopen from the menu at 420 px leaves focus on the trigger.
  • Rebase. The ref now sits on main's direct IconButton and Button children. The hook's header keeps main's text plus one sentence on inert regions, in the shorter form you suggested, and the helper is renamed isInInertRegion.
  • Wording. The description now says "no focus state for this hand-off".

Repeated on this head: 139 tests passed (Comments, the hook, the touch entry, the touch bundle). tsc for Core and Lab: pass. Strict lint and Prettier on the changed files: clean. pnpm review:pre: 0 findings. check:changesets: valid. The changeset now names the more-menu trigger too.

The rest of the stack is unchanged apart from the rebase: #13702, #13735, #13736, #13738, #13739, #13740 and #13741 keep their patch IDs.

@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.

Approved pending CI: CI has not run on this head yet. Mark as resolved and Reopen in Lab's Comments now hand focus to the control that replaces them, or to the more-menu trigger when that control collapses into the menu, and the three points from the last review are fixed. A local browser run puts focus on the trigger at 420 and 480 px and on Reopen, then Mark as resolved, at 560 and 920 px, where the base leaves it on the page body.

Non-blocking: the new comment above the more-menu trigger's ref reads better as two sentences (see the inline note).

Claims and files checked

Review mode: full; reason: author-not-engowner

  • Title, Mark as resolved and Reopen hand focus to the control that replaces them: verified, local browser probe at 920 and 560 px (Reopen, then Mark as resolved) and at 480 and 420 px (the more-menu trigger, the destination the description names); tests at Comments.test.tsx:1228 and :1269.
  • Claim, the change touches none of CommentPin's files and applies cleanly to main on its own: verified, no CommentPin path among the nine files, and the commit merges without conflict onto the stated main commit and onto the current main.
  • Claim, before the change, focus fell to the page body after Mark as resolved and after Reopen: verified, local browser probe of the base (body after Mark as resolved at all four widths, after Reopen at 920 and 560 px), and the test at :1228 fails on the base.
  • Claim, the Comments docs promise focus never drops to the page: verified, Comments.doc.mjs:156.
  • Claim, every other action in the panel keeps focus: reported (a statement about the base's existing behavior).
  • Claim, the overflow list renders each action twice, its inert measuring copy first, so the copy took the hand-off first: verified, OverflowList.tsx:416-431, the probe finds both copies, and useFocusAcrossSwap.test.tsx:295 fails without the inert check.
  • Claim, at 480 px and narrower Reopen collapses into the more menu after it takes focus: verified, local probe (visible action list empty after the resolve).
  • Claim, item, Pagination, Token, TreeList and NavMenu headings already use the hook: verified (Item.tsx:679, Pagination.tsx:424, TokenFocusHandoff.tsx:51, TreeListItem.tsx:448, NavHeadingMenuItem.tsx:174).
  • Claim, when the pressed control leaves while focused, the replacement takes focus: verified, probe and tests above.
  • Claim, if the viewer moved focus first, focus stays where they put it: verified, Comments.test.tsx:1310, and the record is taken only when the leaving control owns focus (useFocusAcrossSwap.ts:113-116).
  • Claim, a failed request replaces nothing, so focus does not move: verified, a local scratch test with a rejecting host keeps the same Mark as resolved element focused.
  • Claim, while the resolve control sits in the more menu, the trigger takes the same ref, the destination Add reaction already uses: verified, CommentActions.tsx:500-507 and :315-318; the test at :1269 fails locally without that ref.
  • Claim, the hook ignores an element inside an inert region and reads inertness each time it records or takes a hand-off: verified, useFocusAcrossSwap.ts:97 and :113; tests at :295 and :304 each fail locally against the matching mutation.
  • Claim, a control first mounted inside an inert region keeps its hand-off once the region is live: verified, useFocusAcrossSwap.test.tsx:304.
  • Claim, core's other callers see no change: verified, the seven caller files (Button, Item, Link, NavHeadingMenuItem, Pagination, TokenFocusHandoff, TreeListItem) each give a hook one element per instance, and the head differs from the base only for an element inside an inert region, which holds no focus.
  • Claim, the internal touch entry re-exports the hook beside isFocusLost and focusForLastInput, outside the public API, with a [chore] Internal: changeset: verified, touch.ts:100-101, :133, touch.test.ts:213, the bundle guard, and the surface generator run locally (0 public rows).
  • Claim, comments keeps no focus state for this hand-off, and the ref sits on the overflow list's direct IconButton and Button children: verified, CommentRow.tsx:383, CommentActions.tsx:415, :428.
  • Claim, core Button marks disabled with aria-disabled: verified, Button.tsx:1153.
  • Authority: the cited focus rule says the component's record names the destination; Comments has no record yet: verified, no Comments record at the head or on main; the future record is reported.
  • Claim, no public API, visual or other behavior change: verified, the surface generator lists no row, and the only behavior change is the claimed Comments focus.
  • Changeset, the hand-off ignores inert elements, the internal entry re-exports it, Comments carries focus to Reopen and back or to the more-menu trigger, apps see no change: verified, as above.
  • Claim, rebased onto main, keeping main's hook header plus an inert-region note and renaming the helper isInInertRegion: verified (the note is two short sentences).
  • Testing: 139 tests pass and the keyboard and inert tests fail without the fix: verified locally (139 passed; 5 failed on the base with the head's tests; each mutation fails its test). Typecheck for Core and Lab, lint, Prettier and the changeset check: verified locally. Pre-review checklist and the author's browser runs and captures: reported.
  • File .changeset/comments-resolve-focus-handoff.md: clear
  • File packages/core/src/internal/touch.ts: clear
  • File packages/core/src/internal/touch.test.ts: clear
  • File packages/core/src/utils/useFocusAcrossSwap.ts: clear
  • File packages/core/src/utils/useFocusAcrossSwap.test.tsx: clear
  • File packages/lab/src/Comments/CommentActions.tsx: non-blocking comment-style note at :501-503
  • File packages/lab/src/Comments/CommentRow.tsx: clear
  • File packages/lab/src/Comments/Comments.test.tsx: clear
  • File scripts/touch-support-bundle.test.mjs: clear

Automated review (maintainer link)

Comment on lines +501 to +503
// While Mark as resolved or Reopen sits in this menu, the
// trigger takes its hand-off, so a pressed control that
// collapses here gives focus to the trigger.

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.

Non-blocking (comment style): this is one 27-word sentence with two topics. Two short sentences read more easily:

              // While Mark as resolved or Reopen sits in this menu, the
              // trigger takes its hand-off. A focused control that collapses
              // here gives focus to the trigger.

This branch was successfully deployed

1 active deployment
Preview — 22561bb0 Deployed Dec 2, 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.

1 participant