Skip to content

fix(Popover): focus, Tab and Escape work in a second document - #7356

Merged
cixzhang merged 1 commit into
meta:mainfrom
vjeux:layer-second-document
Oct 25, 2026
Merged

cixzhang merged 1 commit into
meta:mainfrom
vjeux:layer-second-document

Conversation

@vjeux

@vjeux vjeux commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #7325

User impact

A Popover that an app portals into a second document (a Document Picture-in-Picture window or a same-origin iframe) loses its focus and keyboard model. In Chromium, opening focuses the surface, not the first control. Tab leaves the popover, Escape does nothing with hasLightDismiss={false} and reaches only the browser's close watcher otherwise, and an outside click drops focus to <body>. Keyboard users cannot close a pinned popover and lose their place on close.

Problem and solution fit

The layer runtime reads and listens on the page's global document. Key presses and focus changes reach only their own document, so the shared Escape listener, the focus trap and the activeElement checks miss the second one.

Expected behavior and authority

  • component:Popover (current): FR2 focus entry, AR3 Tab containment, AR4 focus return, and its Escape state.
  • family:overlay-dismissal (current) FR2: one Escape press affects one topmost member.
  • Owner decision: which member is topmost across documents. Proposed there as FR8 and DEC-2, pending owner review: each document ranks its own members, like its browser top layer. The alternative, one order across documents, lets a press in one window dismiss a surface in another.

Smallest restoration

  • layerStack: listens once per document that holds a layer (its container's ownerDocument, else the global document); Escape and isTopmostLayer resolve within it.
  • useFocusTrap and usePopover: listeners, activeElement, focus return and element checks use the container's document and window.
  • Dialog, Lightbox and MobileNav register their dialog element, so a host and its nested layers share one document's order.
  • useLayer: fix: Omit the popover source when the trigger is not an HTML element #7227's invoker-source check now asks the trigger's own window, so an HTML trigger in a second document keeps its source.

No public API, default or visual change.

Evidence

  • Reproduction before the change: a new Chromium spec fails in an iframe and a Picture-in-Picture window; 12 new Vitest cases fail on main.
  • Result after the change: all pass.
  • Representative unchanged path: the page cases pass on both arms; 63 existing layer, popover and focus suites pass.
  • Regression test or other mutation-sensitive proof: those cases.

Writing rubric results

R1 narration: FR8 and DEC-2 are present tense.
R2 research: none.
R3 evidence: the FR8 row names tests and states.
R4 rejected alternatives: one line, in DEC-2.
R5 change references: none.
R6 open questions: none added.

Scope

  • 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

  • Vitest, --maxWorkers=4: Popover/Popover.test.tsx, Layer/useLayerDismissal.test.tsx, hooks/useFocusTrap.test.tsx, Layer/useLayer.test.tsx.
  • Layer, dismissal, Popover, DropdownMenu, Dialog, Tooltip, HoverCard, Lightbox, MobileNav, BottomSheet, Toast, CommandPalette, ContextMenu, Drawer, useMenuHover, useFocusTrap and Lab Comments suites: 63 files, 1585 tests pass.
  • pnpm exec playwright test packages/core/src/Popover/__tests__/PopoverSecondDocument.a11y.chromium.spec.ts --project=chromium, headless Chromium, against a Storybook built with the new story:
    • runtime from main: page 5/5 pass; iframe 0/6 and Picture-in-Picture 0/6. Focus lands on the surface, Tab leaves, Escape leaves the pinned popover open and is not claimed with light dismiss, an outside click leaves focus on <body>, and a press in the second document leaves its own popover open;
    • this branch: 17/17 pass.
  • pnpm -F @astryxdesign/core typecheck, eslint --max-warnings=0 and prettier --check on the touched files, pnpm check:changesets, pnpm check:sync, pnpm check:knowledge: clean.

@vercel

vercel Bot commented Oct 11, 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 Oct 20, 2026 4:54pm UTC

Request Review

@astracat-bot

astracat-bot Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 25, 2026, 5:06 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.

The second-document fix itself checks out: the new Popover, layer-stack and focus-trap tests and the Chromium spec fail without the runtime change and pass on this branch, and the existing overlay suites stay green. Approval waits on a maintainer decision about the dismissal stack: this branch adds one Escape listener per document and ranks Escape presses and platform close requests only among that document's layers, which the overlay-dismissal family contract (a single document-level listener and one topmost order across all registered layers) does not yet state, so its owners need to accept that rule and record it there, or ask for one global order instead. Separately, please split the invokerSource change in useLayer and its two SVG-trigger tests out of this PR (or fold them into #7227): it fixes the SVG-trigger defect #7227 targets, the second-document fix passes without it, and the changeset sentence about the invoker source goes with it.

[Automated review]

let top: DocumentEntry | null = null;
for (const entry of entries) {
if (!isPresentEntry(entry)) {
if (entry.ownerDocument !== doc || !isPresentEntry(entry)) {

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.

This makes the topmost rule per document: an Escape press or close request is ranked only among the layers of its own document, so a layer opened later in an iframe or Picture-in-Picture window no longer outranks the page's top layer, and a press in the page no longer closes it. The overlay-dismissal family contract currently describes a single document-level listener and one topmost order across all registered layers, so its owners need to accept this rule and record it there before this can land.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proposed in docs/families/overlay-dismissal.md, pending owner review, and left to its owners: FR8 says each document ranks its own members (a member belongs to its container's document, or the page's when it registers none) and that FR2 and FR3 apply within that document; DEC-2 records why, with one order across documents as the rejected alternative. The shared-owner line now says one listener in each document that holds a member. No /approve-spec from this side.

Comment thread packages/core/src/Layer/useLayer.tsx Outdated
// order (and its popover nesting) from the trigger rather than from
// its own DOM position. Browsers without the option ignore it.
popover.showPopover({source: triggerRef.current ?? undefined});
popover.showPopover({source: invokerSource(triggerRef.current)});

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.

Without this change an HTML trigger in another document already reaches showPopover as source (the iframe-trigger case passes, and both second-document popovers open in Chromium), so this guard only changes SVG triggers, which is the defect #7227 targets. Please split it and its two SVG-trigger tests out of this PR; the second-document fix passes without it, and the iframe-trigger case can stay as a guard.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split out in 44e34d1: invokerSource and the two SVG-trigger cases are gone, and so is the changeset sentence about the invoker source. The iframe-trigger case stays as a guard: it passes on main and fails against the realm-bound instanceof HTMLElement check in #7227, so whichever of the two lands second has to read the trigger's own window.

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

Modified Components

Lightbox (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 692 -
Complexity N/A Very High (86) -
Popover (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 676 -
Complexity N/A Very High (77) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.9KB 1.2KB

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

40 of 486 shot(s) changed.

A change here is a question, not a failure: check whether the after is the
picture you intended. Record that review on the PR. Baseline maintenance is an
explicit dispatch of CI; this report never rewrites the baseline or adds a release gate.

component story theme mode pixels
Selector Indicator Space Bottom Sheet Narrow End RTL neutral light 754,077
Selector Indicator Space Bottom Sheet Wide Start neutral light 740,188
Chat Full AI Chat probe light 230,823
Chat Full AI Chat probe dark 229,805
RichTextEditor Markdown parity: side by side probe dark 94,866
RichTextEditor Markdown parity: side by side probe light 89,762
Collapsible Dividers probe dark 66,445
Collapsible Dividers probe light 66,445
Chat Default neutral dark 36,304
Chat Default neutral light 35,767
Chat Empty State probe light 23,531
Chat Empty State probe dark 22,622
ChatAutoScroll Scroll Behavior Comparison neutral dark 15,378
ChatAutoScroll Scroll Behavior Comparison neutral light 14,107
Chat With Attachments probe light 13,406
Chat With Attachments probe dark 11,232
ProgressBar With Target Mark probe dark 7,895
ProgressBar With Target Mark probe light 7,895
Markdown Default neutral dark 7,573
Markdown Default neutral light 7,566

and 20 more.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Oct 12, 2026
@vjeux

vjeux commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Proposed; pending owner review, for the owners of family:overlay-dismissal: each document ranks its own layers.

  • A key press and a platform close request reach only the document they happen in, and focus can be in only one document at a time. Each document also keeps its own browser top layer.
  • So the stack listens once in each document that holds a layer and dismisses the topmost layer of the document the person acted in. A press in one window never dismisses a layer in another window they are not looking at, and one press still affects exactly one layer.
  • The alternative is one global order across documents. A press in a Picture-in-Picture window would then close the most recently opened layer of the page behind it, leave the one in front of the person open, and suppress that window's own close watcher.

The diff writes this into the record as FR8 and DEC-2, marked pending owner review. The decision is the owners'; I will not approve this record change myself.

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

The second-document fix works where it is aimed: the new Popover, layer-stack and focus-trap cases and the Chromium spec fail without the runtime change and pass here, and the existing overlay suites stay green. Approval waits on the family:overlay-dismissal owners, who need to approve the proposed FR8 and DEC-2 (one Escape listener per document, with presses and close requests ranked only within their own document) on this head, because the current record states a single document-level listener and one topmost order. Separately, FR8's rule that a member with no container belongs to the page splits a host from what it nests: with a Dialog and a Popover opened inside it both portalled into an iframe, an Escape press in the page now closes the Dialog while the Popover stays open, and the Dialog accepts a platform close request over it, where main gives the Popover the first request. Please rank such members in the document they render in (for example by letting Dialog, Lightbox and MobileNav hand the stack their own element) or otherwise keep a host and its nested layers in one order, cover that case with a test, and have FR8 state the outcome.

[Automated review]

Comment on lines +397 to +398
const ownerDocument =
entry.getContainer?.()?.ownerDocument ?? globalDocument();

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.

Dialog, Lightbox and MobileNav register without getContainer, so this puts them in the page's order even when they render in an iframe or Picture-in-Picture window, while a Popover opened inside them is put in that window's order. With both in an iframe, an Escape press in the page closes the Dialog while its Popover is still open, and the Dialog's close request is accepted over it; on main the Popover gets the first request (FR3/FR4, and the 'Popover inside Dialog' row). Ranking such members in the document they render in (for example, those three hand the stack their own element) or keeping a host and its nested layers in one order would fix it; please add a second-document case for it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in f73440a: Dialog, Lightbox and MobileNav now hand the stack their <dialog> as getContainer, so in an iframe or a Picture-in-Picture window they rank with the layers opened inside them. A new case in Popover.test.tsx puts a Dialog and the Popover inside it in an iframe: an Escape press in the page reaches neither, the Dialog declines a close request while the Popover is open, and Escape in the iframe closes the Popover and then the Dialog. It fails on main (the page press closes the iframe's Popover) and on the previous head (the page press closes the Dialog). Tooltip and HoverCard still register no element; they read their presence from the page's document, so they never take a press in another one, as on main.

Comment thread docs/families/overlay-dismissal.md Outdated
Comment on lines +175 to +181
- **FR8 — Each document ranks its own members.** A member belongs to the
document of the container it registers with, or to the page's document when
it registers none. An Escape press or platform close request is ranked only
among the registered present members of the document it arrives in, and FR2
and FR3 apply within that document; a member of another document is never a
candidate. The stack listens once in each document that holds a member and
stops when its last member leaves. Proposed; pending owner review (DEC-2).

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.

This needs the record owners' approval before the change can land, since the current record states a single document-level listener and one topmost order. As written, 'or to the page's document when it registers none' ranks a Dialog rendered in the second document with the page and a Popover inside it with the second document, which is the cross-window dismissal DEC-2 rejects; FR8 should say how such a member ranks. The FR8 verification row also says 'in Chromium' but names only the two Vitest files, and the Chromium spec never has layers open in two documents at once.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in f73440a, still proposed and pending owner review: FR8 now names the element that places a member in a document (Dialog, Lightbox, MobileNav, BottomSheet, BottomSheetSwitcher and Lab Drawer register their dialog, a focus trap its container; Tooltip and HoverCard register none and stay with the page), and says a host and its nested layers keep one order wherever they render. The FR8 verification is now two rows, one for the Vitest files and one naming PopoverSecondDocument.a11y.chromium.spec.ts, which gained a case with popovers open in the page and in the second document at once: each Escape press closes only the popover of the document it was made in (red on main, green here).

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

The second-document fix works where it is aimed: the new Popover, layer-stack and focus-trap cases fail without the runtime change and pass here, the Chromium spec passes in the page, an iframe and a Picture-in-Picture window, and the earlier Dialog-over-Popover ordering problem is fixed. Approval needs the family:overlay-dismissal owners to update that record for this intentional change: it currently states a single document-level Escape listener and one topmost order, so they need to accept or reject per-document ranking as proposed in FR8 and DEC-2. Separately, FR8 puts Tooltip and HoverCard in the page's document but also says a host and the layers nested in it keep one order wherever they render; a Tooltip shown inside a Dialog in an iframe gets no Escape there (the Dialog closes first), so please have FR8 state that exception or rank hover members in the document they render in.

[Automated review]

Comment thread docs/families/overlay-dismissal.md Outdated
Comment on lines +178 to +182
focus trap its container. A member that registers no element (Tooltip,
HoverCard) belongs to the page's document. An Escape press or platform close
request is ranked only among the registered present members of the document
it arrives in, and FR2 and FR3 apply within that document, so a host and the
layers nested in it keep one order wherever they render. A member of another

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.

FR8 files Tooltip and HoverCard under the page's document, but the next sentence says a host and the layers nested in it keep one order wherever they render. With a Tooltip shown inside a Dialog in an iframe, Escape in the iframe closes the Dialog and never reaches the Tooltip (its presence check reads the page's document), which also leaves the existing 'Tooltip or HoverCard inside Dialog' row unmet there. Please state that exception here and qualify that row, or rank hover members in the document they render in.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stated the exception in 7b56164, still pending owner review: FR8 now says Tooltip and HoverCard register no element and read their presence from the page's document, so they belong to the page and in another document take no request, leaving the first one to their host; the one-order sentence covers members that register an element. A matrix row covers a hover member inside a Dialog in an iframe, and the Tooltip/HoverCard adoption row names the limitation. I kept it in the record rather than changing those two hooks because the gap is not new: on main an Escape in the iframe never reaches the stack, and the Dialog's own close request closes it over the Tooltip there too.

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

The second-document fix works where it is aimed: the new Popover, layer-stack and focus-trap cases fail without the runtime change and pass here, and the Chromium spec passes in the page, an iframe and a Picture-in-Picture window. Approval now waits on the family:overlay-dismissal owners, because this intentionally changes that record: it currently states a single document-level Escape listener and one topmost order, so a maintainer needs to accept or reject per-document ranking as proposed in FR8 and DEC-2. That decision includes the Tooltip/HoverCard exception now written into FR8 and the matrix: inside a Dialog in an iframe or Picture-in-Picture window, the Dialog takes the first Escape while the hover surface is visible, which the existing 'Tooltip or HoverCard inside Dialog' row does not allow. Nothing else needs to change on the code side unless the owners choose a different rule.

[Automated review]

| Platform close request sent to a lower Dialog | Lower Dialog stays open | The platform targets a host; the shared check decides whether it may close |
| Popover in an iframe, Dialog in the page | Request goes to its own document's top member | The app renders into the second document through a portal |
| Popover inside Dialog in an iframe | Popover handles the iframe's first request | Both register their own elements, so they rank in the iframe's order |
| Tooltip or HoverCard inside Dialog, in iframe | The Dialog handles the first Escape there | Hover members register no element and read presence from the page (FR8) |

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.

This row makes it a shared invariant that, in a second document, the Dialog takes the first Escape while a Tooltip or HoverCard inside it is visible. The unchanged row 'Tooltip or HoverCard inside Dialog' above says the present hover surface handles the first Escape, so the two disagree for the same nesting in an iframe or Picture-in-Picture window. Reproduced at this revision: in an iframe, one Escape calls the Dialog's onOpenChange(false) and never reaches the open Tooltip (the same outcome as main, by code reading). This needs the record owners' call together with FR8: accept the exception and qualify the row above, or rank hover members in the document they render in.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Qualified in 323f894 so the proposal no longer contradicts itself: the existing row now reads "Tooltip or HoverCard inside Dialog, in page", and the new row covers the same nesting in an iframe. Whether to accept that exception, or to rank hover members in their own document instead, stays with the record owners together with FR8.

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

The second-document fix works where it is aimed: in an iframe and a Picture-in-Picture window the Popover now takes focus, keeps Tab inside, closes on Escape and returns focus to its trigger, in Chromium and WebKit, and the new tests fail without the runtime change. Approval needs a maintainer of family:overlay-dismissal to update that record for this intentional change, since it currently states a single document-level Escape listener and one topmost order: its owners need to accept or reject per-document ranking as proposed in FR8 and DEC-2, including the Tooltip/HoverCard exception and the narrowing of the existing 'Tooltip or HoverCard inside Dialog' row to the page. Separately, please rebase onto main: the branch now conflicts in docs/families/overlay-dismissal.md and packages/core/src/Layer/useLayerDismissal.ts, and FR8 should say Drawer rather than Lab Drawer now that Drawer is in core.

[Automated review]

| Dialog inside Dialog | Inner dialog handles the first request | Dialog supplies native modality and focus behavior |
| Popover inside Dialog | Popover handles the first Escape | Popover supplies anchoring, portal placement, and focus policy |
| Tooltip or HoverCard inside Dialog | Present hover surface handles the first Escape | Hover families decide when they are present and how controlled state responds |
| Tooltip or HoverCard inside Dialog, in page | Present hover surface handles the first Escape | Hover families decide when they are present and how controlled state responds |

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.

This narrows a current shared invariant ('Tooltip or HoverCard inside Dialog: present hover surface handles the first Escape') to the page. It now agrees with FR8 and with the runtime: in an iframe, one Escape closes the Dialog while its Tooltip stays visible, matching what main does through the browser's close request. Narrowing a current row is still part of the decision the record's owners need to make together with FR8 and DEC-2.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed: the narrowed row is part of the same proposal, left to the record owners with FR8 and DEC-2. No further change from this side unless they choose a different rule.

A Popover that an app portals into a second document (a Document
Picture-in-Picture window, a same-origin iframe) lost its focus and keyboard
model. The layer runtime read and listened on the page's global document,
while key presses and focus changes reach only the document they happen in.

- layerStack: a layer's document is its container's ownerDocument, else the
  global document. The Escape listener goes on with a document's first layer
  and comes off with its last; Escape and isTopmostLayer resolve among the
  layers of that document. Composition is tracked per document.
- useFocusTrap: listeners, activeElement, focus return and element checks use
  the container's document and window.
- usePopover: initial focus reads the element's own document.
- Dialog, Lightbox and MobileNav register their dialog element, so a host and
  the layers nested in it rank in the document they render in.
- useLayer: the invoker source check reads the trigger's own window, so an
  HTML trigger in another document keeps its source.
- family:overlay-dismissal: FR8 and DEC-2, proposed and pending owner review.

Fixes meta#7325

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

The second-document fix works where it is aimed: in a same-origin iframe (Chromium and WebKit) and a Picture-in-Picture window (Chromium) the Popover now takes focus, keeps Tab inside, closes on Escape and returns focus to its trigger, and the new tests fail without the runtime change. Approval needs a maintainer to update family:overlay-dismissal for this intentional change, since it currently states a single document-level Escape listener and one topmost order: they need to accept or reject per-document ranking as proposed in FR8 and DEC-2, including the Tooltip/HoverCard exception and the narrowing of the 'Tooltip or HoverCard inside Dialog' row to the page. The rebase onto main resolved the earlier conflicts, and nothing else needs to change on the code side unless a different rule is chosen.

[Automated review]

cixzhang pushed a commit that referenced this pull request Oct 25, 2026
…8063)

## User impact

On a phone narrower than the drawer, `MobileNav` covered the whole screen: the default 320 px drawer on a 320 px phone left no backdrop to tap, although the `width` prop promises "Capped at 85vw to prevent overflow on small screens". The page the drawer navigates was hidden entirely.

## Problem and solution fit

The drawer's width was `width: 100vw; max-width: <width>px`, which is min(100vw, width): the only cap was the viewport itself. A drawer that covers the screen hides its context and takes away the usual way out, a tap beside it; UIKit's overlay sidebar never covers the whole screen. Small phones, zoomed-in text and split-screen windows reach these widths.

The fix swaps the two: `width: <width>px; max-width: 85vw`, which is min(width, 85vw). On a 320 px phone the drawer is 272 px wide, and a 48 px strip of the dimmed page stays beside it as a target for the tap that closes it.

## Expected behavior and authority

- `MobileNav.doc.mjs`, `width`: "Drawer width in pixels. Capped at 85vw to prevent overflow on small screens."

## Smallest restoration

One style function in `MobileNav.tsx`. No API, token or default changes. From 377 px up, 85vw is at least 320 px, so the default drawer is unchanged there.

Siblings: #8042, #8046 and #8057 also add `ci.yml` steps, and #7358, #7356 and the close-path fix #8064 touch `MobileNav.tsx`; whichever lands second rebases.

## Evidence

Before (`main`) and after, 320 × 568, drawer open:

![320 px before](https://raw.githubusercontent.com/vjeux/astryx/ac3890212337192ec30b259a1b507ad3144c4194/320-before.png)
![320 px after](https://raw.githubusercontent.com/vjeux/astryx/ac3890212337192ec30b259a1b507ad3144c4194/320-after.png)

iOS 26.2 simulator, real taps (402 px: the drawer keeps 320 px): a tap on the strip closes it:

![tap on the strip closes the drawer](https://raw.githubusercontent.com/vjeux/astryx/e56f122761d3eb0ccf94a2a94c461e263bf1dc59/8063-strip-tap-closes.gif)

- Reproduction before the change: on a 320 px phone the drawer is 320 px wide. The new Chromium contract fails against a `main` Storybook (expected 272, received 320).
- Result after the change: a 272 px drawer and a 48 px strip; the strip is backdrop (`elementFromPoint` is the dialog), and a real tap on it closes the drawer.
- Representative unchanged path: on a 402 px phone the drawer keeps its 320 px width and the 82 px strip.
- Regression test or other mutation-sensitive proof: `MobileNavWidth.a11y.chromium.spec.ts` (real Chromium, touch), plus a jsdom test that the drawer's own class declares `max-width: 85vw` and takes its width from the prop.

## Scope

- [x] One defect is restored.
- [x] Separable contradictory or unsettled tagalongs were removed or split.
- [x] No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
- [x] Public text and artifacts contain no internal Meta context.

## Testing

- `pnpm exec vitest run packages/core/src/MobileNav packages/core/src/AppShell`: 136 passed.
- `pnpm -F @astryxdesign/core typecheck`; eslint and prettier on touched files; `pnpm check:repo` (pre-commit).
- `pnpm exec playwright test packages/core/src/MobileNav/__tests__/MobileNavWidth.a11y.chromium.spec.ts --project chromium` against a fresh Storybook build: 2 passed. Against `main`: the 320 px test fails and the 402 px test passes.
- CI: a new "Run MobileNav width contract" step in the a11y contract job, after the Token remove target contract.
@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec bd43bfa

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Oct 25, 2026

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

This looks good to go: the second-document fix restores focus entry, Tab containment, Escape and focus return for a Popover in a same-origin iframe (checked in Chromium and WebKit) and a Picture-in-Picture window (Chromium), and the new tests fail without it. The per-document Escape ranking it relies on (FR8 and DEC-2 in docs/families/overlay-dismissal.md) now has an engineering owner's approval for this exact head, so nothing else is needed from you.

[Automated review]

@cixzhang
cixzhang merged commit 4b05772 into meta:main Oct 25, 2026
54 checks passed
@vjeux
vjeux deleted the layer-second-document branch October 25, 2026 05:09
cixzhang pushed a commit that referenced this pull request Oct 30, 2026
…#8381)

## User impact

**Why:** Keyboard and screen reader users lose their place when a dialog inside an iframe closes: both ways to close it (2 of 2: Escape or a button) send focus to the frame's empty page.

**What:** The dialog now returns focus to the control that opened it, with a ring after a key, none after a click. Picture-in-Picture windows were already fine.

**How to check:** In the "Dialog in a second document" story, open the frame's dialog and press Escape: focus returns to "Open dialog", with its ring.

## Problem and solution fit

What led here: we hit this moving one product onto Astryx, which renders some UI in a second window. Dialog remembers its opener as the page's `document.activeElement`, which for focus inside an iframe is the `<iframe>`. Focusing that `<iframe>` on close moves the frame's focus to its `<body>`.

Options:

- Follow the page's active element into iframes: misses Picture-in-Picture windows, which the page cannot see into.
- Always read the dialog's own document: a page control opening a dialog inside an iframe would lose focus.
- Read the dialog's own document while it has focus, else the page's: covers both. Chosen.

For the ring, Dialog tracks its own document's input, which the page never hears. Skipping its focus call would change the page, where it hides WebKit's ring after a click.

## Expected behavior and authority

`component:Dialog` (current) FR4 and AR2: closing returns focus to the element that opened it. `architecture:interaction-modality` (current) INV1: programmatic focus shows the ring only after keyboard input. Neither is page-only; #7356 fixed this for Popover.

## Smallest restoration

- `Dialog.tsx`: record the opener as above, take the entry direction from its window, return focus with its document's modality.
- Internal utils: `trackInteractionModalityIn(doc)`, counted so the last mounted Dialog removes its listeners; an optional document for `getInteractionModality`; an optional modality for `focusForLastInput`, which checks text fields against their own window. The page's tracker and other callers are unchanged.

No public API, visual or timing change.

## Evidence

- Reproduction before the change: main fails the iframe cases in Chromium and WebKit.
- Result after the change: every case passes.
- Representative unchanged path: the page Dialog passes before and after; the page's modality ignores other documents.
- Regression test or other mutation-sensitive proof: the Testing cases, red without the fix.

## Scope

- [x] One defect is restored.
- [x] Separable contradictory or unsettled tagalongs were removed or split.
- [x] No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
- [x] Public text and artifacts contain no internal Meta context.

## Testing

- Unit tests (Vitest), 115 files and 3137 tests: Dialog and every other component that returns focus or reads the last input. New cases cover a control inside an iframe, a control in the page, a text field, and the input listeners going away when the last Dialog unmounts. Each new case fails on the code from before the fix it covers.
- Browser test in Chromium, 10 cases (`DialogSecondDocument.a11y.browser.spec.ts`): the dialog in the page, an iframe and a Picture-in-Picture window, closed with Escape, with a click, and after a text field opened it, plus a page button that opens a dialog in the iframe. All pass. With the code from before the last review round (0d47027), the iframe and Picture-in-Picture text-field cases fail; with main's `Dialog.tsx`, the iframe cases fail.
- The same test in WebKit 26.5: 7 pass, and the 3 Picture-in-Picture cases are skipped, since only Chromium has that window.
- CI finds the test by its file name (#8367), and its routing line also covers its story and the two utilities. Locally, `pnpm test:a11y-contract:pr origin/main` picks it and passes 115 browser tests.
- Typecheck, repo checks, ESLint and Prettier pass. Merged with our open #7732, #8014 and #7524, typecheck and the utility tests (516) pass; #7525, #7527 and #7529 each merge cleanly with this change.
cixzhang pushed a commit that referenced this pull request Oct 31, 2026
…dow is too short (#9098)

## User impact

When an app renders a `Popover` into a Document Picture-in-Picture window, the popover stops scrolling there. If that window gets shorter than the popover, or its content grows, it is cut off with no scrollbar. In the story's Long list, a 206 px window cut the 260 px list to 174 px, leaving 86 px out of reach of pointer, wheel and keyboard. In the page and in an iframe, it scrolls.

We hit this moving one app onto Astryx. #7356 fixed focus, Tab and Escape there, but the overflow measurement still read the page's window.

## Problem and solution fit

Popover measures overflow again on window resize, visual-viewport resize, a `ResizeObserver` on the surface, mutations and resource loads. The listeners and the `ResizeObserver` came from the page's window:

- a Picture-in-Picture window's resize fires only in that window;
- a `ResizeObserver` the page created checks a box in another window only while the page renders frames, so with the page idle nothing measures again;
- the surface's maximum height follows its own window, so it shrinks but never scrolls.

## Expected behavior and authority

`component:Popover` (current), FR4: "Popover enables internal scrolling only after measured overflow exceeds the current tolerance". PR1 covers its resize observation. Both hold in any window, so neither changes.

## Smallest restoration

The overflow measurement takes the surface's own window, its document's `defaultView`, for its `ResizeObserver`, its resize and visual-viewport listeners and its animation frame. In the page, that window is the page's, so nothing changes. Focus, Tab containment, dismissal and the mutation observer are untouched. The story gains a Long list popover in each document.

Not chosen: only the window listener, since growing content would still go unseen; or a maximum height computed in JavaScript, which duplicates the CSS viewport fit.

## Evidence

- Before (main 0bdda32, Chromium 149, the page hidden and idle, the window really resized to 206 px): the surface is 174 px tall for 260 px of content, overflow-y `visible`.
- After: overflow-y `auto`, and it stops scrolling once the window is tall again.
- Unchanged: the page and iframe cases pass before and after. A page that is drawing frames hides the bug on main.
- Regression tests: the new Vitest case and the two Picture-in-Picture spec cases fail on main and pass with the fix.

## Scope

- [x] One defect is restored.
- [x] Separable contradictory or unsettled tagalongs were removed or split.
- [x] No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
- [x] Public text and artifacts contain no internal Meta context.

## Testing

How to check:
1. In Chrome, open the story "a11y/Popover in a second document" and select Pop out.
2. Make the Picture-in-Picture window taller than the Long list, then open Long list in it.
3. Make the window shorter than the list. Before: the list is cut off and does not scroll. After: it scrolls.

The unit test uses an iframe's window because jsdom has no Picture-in-Picture window. It checks that the measurement listens on the surface's own window. In a real browser an iframe is still covered, because it renders with the page, as the spec's iframe cases show.

Local gates at b1188e7:
- Popover and Layer suites: 331 passed, including the new iframe case, which fails on main.
- `PopoverSecondDocument.a11y.chromium.spec.ts` in Chromium: 23 passed. The two new Picture-in-Picture cases fail on main, and the page and iframe cases pass on both.
- Core typecheck, ESLint with no warnings, Prettier, `pnpm check:repo` and the Storybook build.
- `pnpm test:ui` and `pnpm test:node`: the same failures as on main, none in Popover.

This branch was successfully deployed

1 active deployment
Preview — bd43bfa3 Deployed Oct 20, 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.

[Bug] Popover in a second document (Document Picture-in-Picture): focus, the Tab trap and Escape read the opener's document

2 participants