Repository navigation
fix(HoverCard): Escape and focus work in the card's own document, such as an iframe - #9592
Conversation
component:HoverCard FR6: Escape closes a visible card through the shared dismissal stack. The stack listens in each layer's own document, found through getContainer, but useHoverCard passed none and read the page's document for presence, the focus check, and the focus-into-card check. A card rendered into an iframe or a Picture-in-Picture window therefore never closed on Escape there (WCAG 1.4.13), and focus moving into it closed it. useHoverCard now registers with getContainer: () => triggerRef.current and reads the trigger's ownerDocument wherever it read the page's. Tests: three jsdom cases in a real second document (red before), a Chromium spec over a new no-visual iframe story. Record: FR6 loses its gap sentence, AR2 and Current-state impact drop the other-document gap, and the verification row names the cases.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
|
/approve-spec cf5ab9d |
There was a problem hiding this comment.
Changes requested: the hook change itself works (the three new iframe cases fail on main and pass here), but a record fix and a wording or test fix are needed first.
docs/families/overlay-dismissal.mdstill ends the Tooltip/HoverCard member row with "HoverCard reads its presence from the page's document, so in another document it takes no request (FR8) and returns no focus there (FR9)"; please drop that sentence so it does not contradict the updated FR6.- The changeset and FR6 name Picture-in-Picture windows, but every new case runs in a same-origin iframe; add a Picture-in-Picture case to
HoverCardSecondDocument.a11y.chromium.spec.ts(the Popover second-document spec already has the harness) or narrow the wording to iframes.
Optional: move ownerDocumentOf so the "Focus trigger behavior" doc comment stays on HoverCardFocusTrigger.
[Automated review]
PR Analysis Report🔎 Preview ·
|
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| LayerProvider | 4.2 kB (0) · 20 B CSS (0) | — | ✓ · ✓ · ✗ |
| lab/CommentComposer | 151.7 kB (+128 B) · 1.9 kB CSS (0) | — | — · — · — |
| charts/ChartTooltip | 181.1 kB (+115 B) · 423 B CSS (0) | — | — · — · — |
116 more components
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| ChatComposer | 78.4 kB (+105 B) · 12.0 kB CSS (0) | — | — · — · — |
| charts/Chart | 203.7 kB (+91 B) · 494 B CSS (0) | — | — · — · — |
| lab/CommentThread | 344.0 kB (+90 B) · 2.4 kB CSS (0) | — | — · — · — |
| lab/Comments | 350.8 kB (+78 B) · 2.5 kB CSS (0) | — | — · — · — |
| ChatComposerInput | 76.0 kB (+75 B) · 11.3 kB CSS (0) | — | — · — · — |
| ChatComposerTokenElement | 76.0 kB (+75 B) · 11.3 kB CSS (0) | — | — · — · — |
| HoverCard · Storybook | 28.0 kB (+53 B) · 4.4 kB CSS (0) | 837 (+11) | ✓ · ✓ · — |
| Tokenizer | 91.5 kB (+27 B) · 18.8 kB CSS (0) | — | — · — · — |
| DropdownMenu | 97.3 kB (+26 B) · 17.6 kB CSS (0) | — | — · — · — |
| MoreMenu | 97.5 kB (+25 B) · 17.6 kB CSS (0) | — | — · — · — |
| lab/TourStep | 97.4 kB (+24 B) · 590 B CSS (0) | — | — · — · — |
| lab/Schedule | 106.2 kB (+23 B) · 3.9 kB CSS (0) | — | — · — · — |
| richtext/RichTextEditorToolbar | 278.1 kB (+23 B) · 454 B CSS (0) | — | — · — · — |
| Popover | 91.1 kB (+21 B) · 14.2 kB CSS (0) | — | — · — · — |
| BottomSheet | 68.2 kB (+20 B) · 7.7 kB CSS (0) | — | — · — · — |
| ContextMenu | 108.4 kB (+20 B) · 17.4 kB CSS (0) | — | — · — · — |
| TableCell | 109.6 kB (+20 B) · 17.9 kB CSS (0) | — | — · — · — |
| Avatar | 43.3 kB (+18 B) · 5.5 kB CSS (0) | — | — · — · — |
| MultiSelector | 94.9 kB (+18 B) · 16.8 kB CSS (0) | — | — · — · — |
| PowerSearch | 287.0 kB (+17 B) · 24.1 kB CSS (0) | — | — · — · — |
| lab/CommentPin | 57.3 kB (+16 B) · 1.2 kB CSS (0) | — | — · — · — |
| Dialog | 23.9 kB (+15 B) · 6.9 kB CSS (0) | — | — · — · — |
| SegmentedControl | 96.2 kB (+15 B) · 6.9 kB CSS (0) | — | — · — · — |
| lab/TransferListSelector | 109.1 kB (+15 B) · 1.4 kB CSS (0) | — | — · — · — |
| Slider | 109.3 kB (+14 B) · 8.8 kB CSS (0) | — | — · — · — |
| TableHeaderCell | 109.2 kB (+14 B) · 17.7 kB CSS (0) | — | — · — · — |
| AvatarGroup | 46.1 kB (+13 B) · 5.7 kB CSS (0) | — | — · — · — |
| AvatarGroupOverflow | 49.0 kB (+13 B) · 5.6 kB CSS (0) | — | — · — · — |
| DateTimeInput | 208.4 kB (+13 B) · 18.7 kB CSS (0) | — | — · — · — |
| ToggleButton | 86.8 kB (+13 B) · 10.1 kB CSS (0) | — | — · — · — |
| FileInput | 69.3 kB (+12 B) · 10.9 kB CSS (0) | — | — · — · — |
| Typeahead | 79.8 kB (+12 B) · 12.4 kB CSS (0) | — | — · — · — |
| DropdownMenuSubMenu | 70.4 kB (+11 B) · 9.7 kB CSS (0) | — | — · — · — |
| lab/DialogHeroHeader | 83.4 kB (+11 B) · 372 B CSS (0) | — | — · — · — |
| RadioList | 56.5 kB (+10 B) · 7.3 kB CSS (0) | — | — · — · — |
| SideNavItem | 70.6 kB (+10 B) · 11.1 kB CSS (0) | — | — · — · — |
| Table | 124.9 kB (+10 B) · 18.3 kB CSS (0) | — | — · — · — |
| lab/EmojiPicker | 86.9 kB (+10 B) · 751 B CSS (0) | — | — · — · — |
| Field | 55.1 kB (+9 B) · 7.2 kB CSS (0) | — | — · — · — |
| MobileNav | 70.7 kB (+9 B) · 10.6 kB CSS (0) | — | — · — · — |
| NumberInput | 71.9 kB (+9 B) · 11.4 kB CSS (0) | — | — · — · — |
| StatusDot | 31.4 kB (+9 B) · 5.3 kB CSS (0) | — | — · — · — |
| Tooltip | 29.7 kB (+9 B) · 4.4 kB CSS (0) | — | — · — · — |
| lab/SelectableCardGroup | 64.6 kB (+9 B) · 162 B CSS (0) | — | — · — · — |
| Carousel | 70.0 kB (+8 B) · 10.9 kB CSS (0) | — | — · — · — |
| CommandPalette | 73.3 kB (+8 B) · 12.7 kB CSS (0) | — | — · — · — |
| ComplexSelector | 71.1 kB (+8 B) · 11.8 kB CSS (0) | — | — · — · — |
| FieldLabel | 51.2 kB (+8 B) · 5.7 kB CSS (0) | — | — · — · — |
| lab/ListInput | 88.3 kB (+8 B) · 922 B CSS (0) | — | — · — · — |
| richtext/RichTextEditor | 297.4 kB (+8 B) · 2.6 kB CSS (0) | — | — · — · — |
| richtext/RichTextView | 276.4 kB (+8 B) · 2.3 kB CSS (0) | — | — · — · — |
| AppShell | 91.0 kB (+7 B) · 13.5 kB CSS (0) | — | — · — · — |
| BottomSheetSwitcher | 17.9 kB (+7 B) · 3.4 kB CSS (0) | — | — · — · — |
| ChatLayout | 83.0 kB (+7 B) · 10.5 kB CSS (0) | — | — · — · — |
| CheckboxList | 68.0 kB (+7 B) · 7.7 kB CSS (0) | — | — · — · — |
| InfoTip | 46.8 kB (+7 B) · 5.3 kB CSS (0) | — | — · — · — |
| TextArea | 62.6 kB (+7 B) · 9.3 kB CSS (0) | — | — · — · — |
| TextInput | 67.9 kB (+7 B) · 11.2 kB CSS (0) | — | — · — · — |
| Thumbnail | 64.8 kB (+7 B) · 11.6 kB CSS (0) | — | — · — · — |
| lab/DiffViewer | 87.4 kB (+7 B) · 2.1 kB CSS (0) | — | — · — · — |
| lab/TransferList | 101.6 kB (+7 B) · 1.2 kB CSS (0) | — | — · — · — |
| AlertDialog | 105.5 kB (+6 B) · 14.6 kB CSS (0) | — | — · — · — |
| InputGroup | 56.7 kB (+6 B) · 7.8 kB CSS (0) | — | — · — · — |
| Link | 53.2 kB (+6 B) · 7.0 kB CSS (0) | — | — · — · — |
| ListItem | 70.4 kB (+6 B) · 11.4 kB CSS (0) | — | — · — · — |
| Pagination | 110.0 kB (+6 B) · 17.8 kB CSS (0) | — | — · — · — |
| SideNav | 114.2 kB (+6 B) · 11.4 kB CSS (0) | — | — · — · — |
| SideNavHeading | 75.7 kB (+5 B) · 11.3 kB CSS (0) | — | — · — · — |
| Switch | 103.9 kB (+5 B) · 9.9 kB CSS (0) | — | — · — · — |
| TopNav | 72.4 kB (+5 B) · 10.9 kB CSS (0) | — | — · — · — |
| TopNavHeading | 75.3 kB (+5 B) · 11.2 kB CSS (0) | — | — · — · — |
| BreadcrumbItem | 84.8 kB (+4 B) · 12.1 kB CSS (0) | — | — · — · — |
| CheckboxInput | 64.4 kB (+4 B) · 9.2 kB CSS (0) | — | — · — · — |
| Markdown | 187.6 kB (+4 B) · 20.6 kB CSS (0) | — | — · — · — |
| RadioListItem | 67.6 kB (+4 B) · 10.1 kB CSS (0) | — | — · — · — |
| Selector | 99.9 kB (+4 B) · 17.4 kB CSS (0) | — | — · — · — |
| TimeInput | 162.2 kB (+4 B) · 16.0 kB CSS (0) | — | — · — · — |
| BaseTypeahead | 71.2 kB (+3 B) · 10.9 kB CSS (0) | — | — · — · — |
| Button | 60.4 kB (+3 B) · 10.0 kB CSS (0) | — | — · — · — |
| TabMenu | 71.9 kB (+3 B) · 11.1 kB CSS (0) | — | — · — · — |
| DateInput | 186.7 kB (+2 B) · 17.0 kB CSS (0) | — | — · — · — |
| Lightbox | 122.6 kB (+2 B) · 10.6 kB CSS (0) | — | — · — · — |
| Timer | 14.0 kB (+2 B) · 6.0 kB CSS (0) | — | — · — · — |
| Calendar | 71.4 kB (+1 B) · 10.6 kB CSS (0) | — | — · — · — |
| ChatDictationButton | 61.0 kB (+1 B) · 10.0 kB CSS (0) | — | — · — · — |
| CodeBlock | 75.4 kB (+1 B) · 11.3 kB CSS (0) | — | — · — · — |
| CommandPaletteInput | 31.7 kB (+1 B) · 7.5 kB CSS (0) | — | — · — · — |
| DrawerHeader | 63.4 kB (+1 B) · 12.9 kB CSS (0) | — | — · — · — |
| MobileNavToggle | 60.7 kB (+1 B) · 10.0 kB CSS (0) | — | — · — · — |
| TopNavMenu | 74.7 kB (+1 B) · 11.2 kB CSS (0) | — | — · — · — |
| charts/ChartLegend | 49.5 kB (0) · 224 B CSS (0) | — | — · — · — |
| Banner | 62.4 kB (0) · 10.5 kB CSS (0) | — | — · — · — |
| ChatLayoutScrollButton | 60.9 kB (0) · 10.2 kB CSS (0) | — | — · — · — |
| ChatMessageList | 28.1 kB (0) · 7.0 kB CSS (0) | — | — · — · — |
| ChatSendButton | 60.8 kB (0) · 10.0 kB CSS (0) | — | — · — · — |
| ChatToolCalls | 32.0 kB (0) · 8.3 kB CSS (0) | — | — · — · — |
| DateRangeInput | 92.8 kB (0) · 12.5 kB CSS (0) | — | — · — · — |
| DialogHeader | 63.2 kB (0) · 11.5 kB CSS (0) | — | — · — · — |
| Heading | 12.4 kB (0) · 5.4 kB CSS (0) | — | — · — · — |
| IconButton | 60.5 kB (0) · 10.0 kB CSS (0) | — | — · — · — |
| ProgressBar | 11.7 kB (0) · 6.3 kB CSS (0) | — | — · — · — |
| Spinner | 24.7 kB (0) · 6.2 kB CSS (0) | — | — · — · — |
| Stepper | 62.0 kB (0) · 10.1 kB CSS (0) | — | — · — · — |
| TableSelectionToolbar | 70.7 kB (0) · 13.2 kB CSS (0) | — | — · — · — |
| Text | 11.8 kB (0) · 5.4 kB CSS (0) | — | — · — · — |
| Timestamp | 33.2 kB (0) · 10.2 kB CSS (0) | — | — · — · — |
| lab/ChatReactionBar | 107.1 kB (0) · 1.1 kB CSS (0) | — | — · — · — |
| CheckboxListItem | 71.4 kB (−1 B) · 11.4 kB CSS (0) | — | — · — · — |
| SideNavCollapseButton | 61.2 kB (−1 B) · 10.0 kB CSS (0) | — | — · — · — |
| lab/LineClamp | 14.0 kB (−1 B) · 168 B CSS (0) | — | — · — · — |
| Drawer | 50.7 kB (−3 B) · 8.3 kB CSS (0) | — | — · — · — |
| Toast | 98.3 kB (−5 B) · 10.3 kB CSS (0) | — | — · — · — |
| TopNavMegaMenu | 69.9 kB (−8 B) · 11.8 kB CSS (0) | — | — · — · — |
| lab/ChatEmojiPicker | 105.9 kB (−9 B) · 773 B CSS (0) | — | — · — · — |
| layer | — | — | — · ✓ · — |
| Layer | — | — | ✓ · ✓ · — |
Package size: @astryxdesign/core 7.20 MB packed (+797 B); no new dependencies.
API changes: none in this pull request
Committed API report behind this build: cli 29 rows, core 34 rows, theme-butter 1 row, theme-y2k 1 row; run pnpm api:report.
Touched components checked; add ci:run-visual or ci:run-rtl to run the full suites.
Generated by PR Enrichment workflow | View full report
…ent; add the Picture-in-Picture case CodeBunny on #9592: the family record's Tooltip/HoverCard row still said HoverCard reads its presence from the page's document; that sentence goes, and the FR8/FR9 evidence row names HoverCard's second-document checks. The story gains a Pop out button that portals the card into a Document Picture-in-Picture window, and the Chromium spec checks Escape and the focus return there too, so the changeset's Picture-in-Picture claim has a test. The ownerDocumentOf helper moves above HoverCardFocusTrigger's doc comment, and the readiness count drops to seven gaps.
|
/approve-spec b3b8e9f |
There was a problem hiding this comment.
Changes requested: the hook fix works in both an iframe and a Picture-in-Picture window, but the new Picture-in-Picture Chromium case cannot pass as written.
- In
HoverCardSecondDocument.a11y.chromium.spec.ts, the secondtrigger.hover()(line 97) lands where the pointer already rests, so nomouseenterfires and line 98 times out; addingawait pictureInPicture.mouse.move(0, 0);before it makes all three cases pass.
Optional: the change also lets a card whose trigger sits inside a raw useFocusTrap container take Escape before that trap in the page, which deserves a line in the changeset, and ownerDocumentOf's comment can keep only its reason.
[Automated review]
…e hovering it again CodeBunny on #9592: the second hover landed where the pointer already rested, so no mouseenter fired; the case moves the pointer away first. The changeset notes that a card inside a focus-trap container now takes Escape before it, and ownerDocumentOf's comment keeps only its reason.
|
/approve-spec e53260c |
There was a problem hiding this comment.
Changes requested: the second-document fix works in an iframe and a Picture-in-Picture window (the new jsdom cases fail on main and pass here, and all three Chromium cases pass), but two things need fixing first.
- A
useHoverCardtrigger rendered after the hook mounts, inside a second document, leaves the card registered in the page, so Escape pressed in the page closes that card and Escape in its own document does nothing; register once the trigger exists, in its document, and add a case for it. - The changeset says a card inside a focus-trap container now takes Escape first, but no test covers it and the description still says nothing changes in the page, so add a case and update the description.
[Automated review]
…ard-escape-owner-document # Conflicts: # docs/families/overlay-dismissal.md # docs/specs/components/HoverCard/HoverCard.spec.md # packages/core/src/HoverCard/HoverCard.test.tsx # packages/core/src/HoverCard/useHoverCard.tsx
…ttaches The dismissal stack listens in the document a layer registers with. A useHoverCard trigger rendered after the hook mounts used to leave the card registered in the page, so Escape in its own document did nothing. The card now registers once its trigger is attached. New cases cover that and a trigger inside a focus-trap container taking Escape first.
|
/approve-spec 5451bcd |
There was a problem hiding this comment.
Changes requested: the second-document fix now registers a trigger attached after mount in its own document, and the focus-trap ranking is tested and described, but three things need fixing first.
- A
useHoverCardtrigger that moves between documents while the hook stays mounted keeps its first registration, so Escape pressed in the page closes a card in the frame and, after a move back, Escape in the page no longer closes it; re-register whenever the trigger attaches in a different document, in the shared dismissal owner, and add a case that moves one trigger into the frame and back. - The trigger's
Documentis kept in React state (useHoverCard.tsx:316), which the React runtime rules forbid for DOM nodes, so drop it with the fix above or gate registration on a boolean instead (this corrects my earlier suggestion to hold the document in state). - Regression: since the latest merge of
main, lint rejects the@playwright/testimport inHoverCardSecondDocument.a11y.chromium.spec.tsand CI's lint job fails on it, so importexpect,testandtype Pagefrom@astryxdesign/a11y-spec/playwright, as the Popover second-document spec does.
[Automated review]
…ocument A trigger that moves between documents kept the card's first registration, so Escape reached the wrong document. useHoverCard now counts the trigger's documents in a key, and an internal keyed form of useLayerDismissal registers again when the key changes. The document itself is no longer held in React state. The second-document browser spec imports Playwright through the a11y-spec wrapper.
|
/approve-spec 0169d99 |
There was a problem hiding this comment.
Approved pending CI: the test check is still running on this head; every other check has passed.
The last review's three blockers are fixed: a useHoverCard trigger that moves between documents now registers again where it lands, the trigger's document stays out of React state, and the Chromium spec imports through the a11y-spec wrapper. Every new case fails on main and passes here, and the Chromium spec passes on this head's Storybook build.
Optional, non-blocking:
- Two comments in
useHoverCard.tsxcan be shorter and more exact; see the inline suggestions. - Name
HoverCardSecondDocument.a11y.chromium.spec.tsin the HoverCard and overlay-dismissal verification rows, as the Popover row names its spec. - The description still counts five new cases and 87 tests; the head has six and 88.
[Automated review]
| // The dismissal stack listens in the document a layer registers with, so | ||
| // the card registers when its trigger attaches, and again when the trigger | ||
| // attaches in another document. The key counts those documents. |
There was a problem hiding this comment.
Non-blocking: the first sentence runs to 28 words, and the key does not count documents: it changes on every move, so page, frame, page reaches three. Shorter:
// The stack listens in the document the card registers with. The key changes
// each time the trigger attaches in a different document, so the card
// registers there again.| // Registered from the trigger's attach for the hook's lifetime, in the | ||
| // trigger's document, rather than gated on `layer.isOpen`: | ||
| // that state can lag a frame behind the DOM, so a press arriving right after | ||
| // the layer appears would find nothing registered. Because this layer |
There was a problem hiding this comment.
Non-blocking: this still opens with a 40-word sentence. Shorter:
// Registered once the trigger attaches, in its document. Not gated on
// `layer.isOpen`: that state can lag a frame behind the DOM, so a press right
// after the layer appears would find nothing registered.…ard-escape-owner-document # Conflicts: # docs/specs/components/HoverCard/HoverCard.spec.md
|
/approve-spec f76cf39 |
There was a problem hiding this comment.
Approved pending CI: one unit test shard, test-ui (4/4), is still running on this head; every other check has passed.
Merging main keeps the second-document fix intact: the six new cases still fail on main and pass here, and the Chromium spec passes in an iframe and in a Picture-in-Picture window on this head's Storybook build.
Optional, non-blocking:
- The two earlier inline suggestions on comments in
useHoverCard.tsxstill apply. - Add a case for a controlled close with focus inside a card in a second document (
useHoverCard.tsx:652-654). - Name
HoverCardSecondDocument.a11y.chromium.spec.tsin the HoverCard and overlay-dismissal verification rows, as the Popover row names its spec. - The description still counts five new cases and 87 HoverCard tests; the head has six and 89.
[Automated review]
User impact
An app renders a
HoverCardinto a second document, such as a same-origin iframe or a Document Picture-in-Picture window, and the user works there:In the page itself, one thing changes: a card whose trigger sits inside a focus-trap container now takes Escape before that container, as the topmost layer. Before, the container took the press and the card stayed open.
Problem and solution fit
getContainer.useHoverCardpassed none, so the stack listened only in the page's document. The hook also looked up its card, and the focused element, in the page's document. In a second document the card is never found, so the hook reads it as closed, and focus moving into it reads as focus leaving.Expected behavior and authority
component:HoverCardFR6 (current): Escape closes a visible card through the shared dismissal stack. The record lists the other-document failure as an implementation gap under Current-state impact, and AR2 cites WCAG 1.4.13.family:overlay-dismissal: the stack routes a press to the top-most layer of the document it arrived in.Smallest restoration
useHoverCardregisters withgetContainer: () => triggerRef.current, once its trigger is attached, so a trigger rendered after the hook mounts still registers in its own document. It also reads the trigger'sownerDocument(a smallownerDocumentOfhelper) in the four places that read the page'sdocument: Escape presence, the Escape focus check, the controlled-close focus check, and the focus-into-card check.family:overlay-dismissaldrops the Tooltip/HoverCard row's sentence that HoverCard reads the page's document, and its FR8/FR9 evidence row names HoverCard's second-document checks.Evidence
HoverCard.test.tsxfail on main:useHoverCardtrigger rendered there after the hook mounts leaves Escape in that document doing nothing (this one also fails at the previous head of this PR);useFocusTrapcontainer loses Escape to the container.useLayerDismissal.test.tsxpass unchanged (93 tests).HoverCardSecondDocument.a11y.chromium.spec.tsdrives a new no-visual story in Chromium, in a same-origin iframe and in a Document Picture-in-Picture window (Pop out): Escape pressed there closes the card, and Escape from inside the card returns focus to the trigger.Scope
Testing
pnpm vitest run packages/core/src/HoverCard packages/core/src/Layer/useLayerDismissal.test.tsx: 93 passed.pnpm check:knowledge: aligned.Writing rubric results
Run over the FR6 row, AR2, Current-state impact, the FR4–FR6 verification row, and
family:overlay-dismissal's Tooltip/HoverCard and FR8/FR9 rows (docs/contributing/spec-writing.md):family:overlay-dismissal.