Repository navigation
fix(Comments): after a focused Mark as resolved or Reopen, or one picked from the more menu, focus stays in the comment's header in a narrow comment - #14251
Conversation
…tion collapses (debug logs, not for review)
… after the list reports the collapse
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
|
/approve-spec 65931a4 |
PR Analysis Report
Generated by PR Enrichment workflow | View current CI run |
There was a problem hiding this comment.
Changes requested: the hand-off to the more menu button works for a keyboard Mark as resolved in a narrow header (reproduced locally in Chromium on the Margin Comment story, and the new test fails without the fix), but three points need fixing first.
- Reopen picked from the more menu still drops focus to the page: in a narrow resolved comment Reopen lives in the more menu, and picking it brings Mark as resolved back to the header and unmounts the now-empty menu with focus on
<body>(reproduced locally in Chromium on this branch), so either focus the replacing header control from that menu item's handler, aspickReactiondoes, or narrow the new docs sentence and the description to the header-button case. - A second focus tracker beside
useFocusAcrossSwapmisses focus inside a shadow root:trackResolveControlcopies the shared hook's detach-time focus capture but readsnode.ownerDocument.activeElementinstead of the hook's shadow-awareownsFocus, so in a shadow root the hand-off never fires (reproduced locally in jsdom) and the title, changeset and docs sentence are untrue there, so please extenduseFocusAcrossSwapwith a fallback target for a replacement that collapses and drop the component-level tracker. - The title claims the hand-off for presses that leave the control unfocused: a Safari pointer press never focuses the button and a host may resolve after the viewer moved focus away, and focus rightly stays put in both cases, so retitle to something like "when a focused Mark as resolved or Reopen is replaced and the header has no room for the replacement, focus goes to the more menu button".
- The file header and two new comments need a touch-up: the
@inputheader omits the newisFocusLostimport, and "The menu stays closed." and "Moves focus to the more menu's trigger once it is in the document." restate the code (non-blocking).
Claims and files checked
Review mode: full; reason: no-earlier-review
- Claim (title): after Mark as resolved or Reopen, focus goes to the more menu button when the header has no room: false for presses that never focus the control, and inside a shadow root.
- Claim (changeset): in a narrow comment focus moves to the more menu button instead of the page, menu closed: verified for keyboard and Chromium mouse (local Chromium capture;
Comments.test.tsx:1269); false inside a shadow root (local jsdom probe). - Claim: on main a keyboard Mark as resolved in a narrow comment loses focus: verified (local Chromium capture on main:
<body>). - Claim: the header has no room for Reopen, so it collapses into the more menu: verified (capture: no header actions after resolving).
- Claim: Reopen from a narrow resolved comment loses focus the same way: verified on main, and still true on this branch, so false as a fixed case.
- Claim: the earlier hand-off still focuses a replacement that shows in the header: verified (existing test passes locally).
- Claim: the docs promise focus never drops to the page: verified (
Comments.doc.mjs:156), still false for Reopen from the menu. - Claim: the focus spec asks a component to name the destination: verified on main; Lab is exempt.
- Claim: the menu stays closed: verified (
aria-expanded="false"in the test and the capture). - Claim: no focus moves when the control did not have focus: verified (
Comments.test.tsx:1307;CommentActions.tsx:299). - Claim: specs ruled the case decided: reported; no record linked, and Lab is exempt.
- Claim (new docs sentence): the two actions hand focus to each other, else to the more menu button: false (Reopen from the menu; shadow root).
- Claim: the resolve control's ref records focus at detach until the commit's work ends: verified (
CommentActions.tsx:292-309). - Claim: the overflow report marks the hand-off pending: verified (
CommentActions.tsx:359-368). - Claim: the cluster's ref, or the more menu's ref when the menu mounts, focuses the button when focus is on the page: verified (
CommentActions.tsx:371-383,:451-455,:548-551; capture where the menu mounts). - Claim: no Effect, no new prop, no Core change: verified (diff).
- Claim: the new test fails with main's component and passes here: verified (run locally; main's file leaves focus on
<body>). - Claim: the other two named tests pass: verified (run locally).
- Claim: Chrome stills table: reported, not present in the description.
- Claim (scope): Comments only, four files: verified (changed-file list).
- Claim (checklist): one defect restored: false in part (Reopen from the menu); no new public API: verified; no internal context in public text: verified.
- Claim (testing): 4 files, 103/103: verified (run locally); lab
tscclean: verified (run locally after building Core);eslintonCommentActions.tsxclean: verified (run locally). - Claim (overlap): #14155 merged and #13740 open and editing the same file: verified (GitHub); #13741 is stacked on #13740 and leaves
CommentActions.tsxalone: verified (GitHub), its line overlap in the docs and tests unchecked. - File
.changeset/comments-more-menu-resolve-focus.md: untrue inside a shadow root (second finding). - File
packages/lab/src/Comments/CommentActions.tsx: first and second findings; header and comment touch-up. - File
packages/lab/src/Comments/Comments.doc.mjs: first and second findings. - File
packages/lab/src/Comments/Comments.test.tsx: clear.
… header button that replaces it; the focus check reads the control's own root
…s keeps focus on its trigger
…Swap, with the more menu in the resolve control's swap
|
/approve-spec 4af7de6 |
There was a problem hiding this comment.
Changes requested: the hand-off to the more menu button now works for a focused Mark as resolved in a narrow header, including when the menu already exists and inside a shadow root (reproduced locally in Chromium, and the new tests fail on main), but two points need fixing first.
- A Reopen picked from the more menu still drops focus to the page: in the Margin Comment story (reproduced locally in Chromium, keyboard and mouse) the real OverflowList attaches Mark as resolved one commit before the emptied menu unmounts, so
useFocusAcrossSwaphas no attaching node to hand focus to and it lands on<body>, while the new test passes only because its OverflowList stand-in renders and reports in one commit; please move focus to the visible replacing control when the more menu leaves holding focus (or give the hook the fallback target the description defers), make the stand-in report a commit after it renders, and reword the title, docs row, changeset and description, which also misdescribe a menu that keeps other items, where focus rightly returns to the more menu button. - The Testing line reports the earlier head's test count: the four Comments test files hold 106 tests at this head (all pass, run locally), not 103.
resolveFocusTargettook overThreadSurface's JSDoc: the new helper sits between that comment block andThreadSurfaceinCommentRow.tsx, so move it above the block (non-blocking).- The file header and two comments still need a touch-up: the
@inputheader omitsisFocusLost, and "The menu stays closed." and "Moves focus to the more menu's trigger once it is in the document." restate the code (non-blocking).
Claims and files checked
Review mode: incremental; reason: none
- changed rules (0): none
- Claim (title): a focused Mark as resolved or Reopen, or one picked from the more menu, keeps focus in the header of a narrow comment: false for a menu pick in the Margin Comment story (Chromium:
<body>); true for the focused header button. - Claim: on main, a keyboard Mark as resolved in a narrow comment loses focus: verified (Chromium on main:
<body>). - Claim: on main, a Reopen picked from the more menu of a narrow resolved comment loses focus the same way: verified (Chromium on main:
<body>). - Claim: a focused header button replaced by an action with no room hands focus to the more menu button, menu closed: verified (new test; Chromium in the Margin Comment story and in a viewer-owned thread whose menu already exists).
- Claim: a menu pick replaced by a header button hands focus to that button: false (Margin Comment:
<body>; a menu that keeps other items keeps focus on its own button). - Claim: a control without focus moves no focus: verified (test passes).
- Claim: a replacement shown in the header still takes focus, as before: verified (existing test passes).
- Claim: the docs promise focus never drops to the page: verified that the row says so; still false for a menu pick.
- Claim: the focus case was ruled decided: reported; no ruling linked, and this Lab-only change needs none.
- Claim: the detach mark reads the control's own root, so a shadow root works: verified (shadow-root test passes here and fails on main).
- Claim: the overflow report marks the hand-off pending, and the cluster's or menu's ref then focuses the button: verified (
CommentActions.tsx:366-390,:394-403,:471-475). - Claim: the more menu in the shared swap hands a menu pick's focus to the header button: false in Chromium (first finding); a first collapse that mounts the menu hands focus to its button: verified.
- Claim: the shared hook cannot serve a replacement rendered into a menu already present: verified (it focuses only a node that attaches); the later hook change is reported.
- Claim: no Effect, no new prop, no Core change: verified (diff).
- Claim: the collapse regression test fails with main's component and passes here: verified (run locally).
- Claim: the menu-pick and shadow-root tests cover those paths: shadow root verified; the menu-pick test passes only against the stand-in (first finding).
- Claim: the menu-stays test covers a menu that keeps other items: verified (passes here and on main).
- Claim: Chrome stills table: reported, not present in the description.
- Claim (scope): Comments only, five files: verified (changed-file list).
- Claim (checklist): one defect restored: false in part (first finding); no tagalongs, no new public API, no internal context in public text: verified.
- Claim (testing): 4 files, 103/103: false count (106 at this head); lab
tscclean andeslintclean: verified (run locally: labtscexits 0 after building Core;eslintreports no errors on the three changed source files) - Claim: the new test fails with main's component file and passes here: verified (run locally).
- Claim (overlap): the earlier focus fix merged; the API pass also edits
CommentActions.tsx; the stacked follow-up touches none of these lines: verified (GitHub). - Claim (changeset): both actions keep focus off the page in a narrow comment: false for a menu pick (first finding); the no-room hand-off: verified; the menu-pick hand-off: false.
- File
.changeset/comments-more-menu-resolve-focus.md: first finding. - File
packages/lab/src/Comments/CommentActions.tsx: first finding; header and comment touch-up. - File
packages/lab/src/Comments/CommentRow.tsx: first finding; JSDoc placement. - File
packages/lab/src/Comments/Comments.doc.mjs: first finding. - File
packages/lab/src/Comments/Comments.test.tsx: first finding (stand-in timing); second finding (count).
| {additionalActions} | ||
| {items.length > 0 && ( | ||
| <HStack data-comment-more-menu="true"> | ||
| <HStack ref={attachMoreMenu} data-comment-more-menu="true"> |
There was a problem hiding this comment.
In the Margin Comment story this hand-off never fires (reproduced locally in Chromium, keyboard and mouse: focus ends on <body> after Reopen is picked). The real OverflowList attaches Mark as resolved in its measurement commit, and only the report commit that follows empties items and unmounts this wrapper, so when it leaves holding focus no node attaches through the shared ref. One fix: in this ref's cleanup, when the trigger holds focus and visibleCommentAction(clusterRef.current, resolveAction.kind) exists, focus that control.
| it('hands focus to Mark as resolved after Reopen is picked from the more menu', async () => { | ||
| // Only Reopen collapses, so the more menu empties and unmounts once Mark | ||
| // as resolved replaces it in the header. | ||
| overflowControl.collapsed = new Set(['reopen']); |
There was a problem hiding this comment.
This passes only because the OverflowList stand-in renders the new header button and drops the menu in one commit: it never calls onOverflowChange when nothing collapses (line 78), so collapsed stays {'reopen'} and the menu empties at once. The real OverflowList reports a commit later. A stand-in that reports in a later commit than it renders (or a browser test of the Margin Comment story) would catch the regression.
| criterion: '2.4.3 Focus Order', | ||
| description: | ||
| 'Focus never drops to the page. After a delete it moves to the next thread, or to the thread when a reply was deleted. Load earlier comments keeps focus on itself, or on the Retry that replaces it when loading fails. A thread selected when the panel mounts opens without taking focus.', | ||
| 'Focus never drops to the page. Mark as resolved and Reopen hand focus to each other. When the header has no room for the one that replaces it, focus goes to the more menu button that holds it; when one picked from the more menu is replaced by a header button, that button takes focus. After a delete it moves to the next thread, or to the thread when a reply was deleted. Load earlier comments keeps focus on itself, or on the Retry that replaces it when loading fails. A thread selected when the panel mounts opens without taking focus.', |
There was a problem hiding this comment.
"when one picked from the more menu is replaced by a header button, that button takes focus" is false twice at this head: in the Margin Comment story focus lands on <body> (reproduced locally in Chromium), and when the menu keeps other items focus returns to the more menu button, as the new test at Comments.test.tsx:1350 asserts. The changeset says the same.
|
|
||
| // The resolve control's focus swap includes the comment's more menu, whose | ||
| // focus target is its trigger button. | ||
| function resolveFocusTarget(node: HTMLElement): HTMLElement | null { |
There was a problem hiding this comment.
Non-blocking: this helper now sits between ThreadSurface's JSDoc (lines 183-189) and ThreadSurface, so that description attaches to resolveFocusTarget. Moving the helper above the JSDoc block keeps both documented.
…visible replacing control; the stand-in can report a commit later
|
/approve-spec 91a636f |
User impact
In a narrow comment, such as the Margin Comment story, a keyboard user who presses Mark as resolved loses focus to the page. The comment header has no room for Reopen, so OverflowList puts it in the more menu, and the control that replaced the pressed one is never on screen. The user must tab from the top of the page back to the thread. Reopen from a narrow resolved comment does the same. And when Reopen or Mark as resolved is picked from the more menu, the header button that replaces it appears while the now-empty menu goes, so focus falls to the page there too.
Problem and solution fit
spec:AST-085FR4 requires the component to name where focus goes when it removes a focused control.When the focused header button is replaced by an action the header has no room for, Comments moves focus to the comment's more menu button, the visible control that now holds it. The menu stays closed. When the action was picked from the more menu and a header button replaces it, that button takes focus, as
pickReactionalready does for Add reaction. If the menu still holds other actions, it stays, and focus returns to the more menu button. A thread whose resolve control did not have focus moves no focus, and a resolve whose replacement shows in the header still hands focus to it, as #14155 does.Expected behavior and authority
spec:AST-085FR4 (when a component removes a focused control, the component names where focus goes). Specs ruled this case records-decided: the destination is the control that replaces the pressed one, or the visible control that holds it, which here is the more menu button.Smallest restoration
CommentActions.tsxandCommentRow.tsx: the resolve control's ref records, when it detaches, whether it had focus, until the end of that commit's work. It reads focus from the control's own root (getRootNode().activeElement), so a Comments panel in a shadow root works too.onOverflowChangereport, the callback that says which actions collapsed, marks the hand-off pending when the replacing action is among them.useFocusAcrossSwapref, with agetFocusTargetthat resolves it to its trigger. So when an action picked from the menu is replaced by a header button and the emptied menu goes in the same commit, Core's hook hands focus to that button, and a first collapse that mounts the menu hands focus to its trigger. The real OverflowList can show the replacing button one commit before the emptied menu goes, so nothing attaches after the menu: then the menu's own ref, as it leaves holding focus, focuses the visible replacing control.useFocusAcrossSwaphas no fallback-target option for that, so the small local hand-off (the detach mark and the overflow report) covers it until the hook gains that option, which is tracked to land, with this code removed, before Comments moves to Core.Comments.doc.mjsnames the case in "Focus after changes".Evidence
Comments.test.tsxcan report a commit after it renders (reportsLate), as the real list measures first; "hands focus to Mark as resolved after a menu pick when the list reports a commit later" uses it.Comments.test.tsx: "hands focus to the more menu trigger when Reopen collapses into it". It fails with main'sCommentActions.tsx(focus on<body>) and passes here.Branded Chrome stills
Google Chrome on macOS through the repository's stills workflow, at
1b05dee2(this head adds only a test wait). Each cell drives the Margin Comment story with the keyboard and checks the focused element in real Chrome before the still: a cell fails if focus is anywhere else.Scope
Components: Comments.
Files:
packages/lab/src/Comments/CommentActions.tsx,CommentRow.tsx,Comments.test.tsx,Comments.doc.mjs, and the changeset.changeset/comments-more-menu-resolve-focus.md.Testing
tsc(lab) clean;eslintonCommentActions.tsxclean (Linux).CommentActions.tsxand passes with this branch's.Overlap checked: #14155 (merged; this fills its known gap, the More-menu case), #13740 (ernestt's Comments API pass; it also edits
CommentActions.tsx, so whichever lands second merges main), #13741 (stacked on #13740; no overlap with these lines)