An open source design system that's fully customizable and agent ready
TypeScript
spec(overlay-dismissal): trigger-anchored overlays work in iframes and PiP windows (FR8) (#9142)
Cindy Zhang717c8009612c
diff --git a/docs/families/overlay-dismissal.md b/docs/families/overlay-dismissal.mdindex 07a0af1878..e270e45e11 100644--- a/docs/families/overlay-dismissal.md+++ b/docs/families/overlay-dismissal.md@@ -7,7 +7,7 @@ authority: currentarchive_reason: nullsuperseded_by: nullapproved_by: cixzhang-approved_at: 2026-08-30+approved_at: 2026-10-31owners: [cixzhang, imdreamrunner]review_triggers: [behavior, accessibility]verified_by:@@ -22,6 +22,7 @@ verified_by:packages/core/src/CommandPalette/CommandPalette.test.tsx,packages/core/src/Popover/Popover.test.tsx,packages/core/src/Popover/__tests__/PopoverSecondDocument.a11y.chromium.spec.ts,+ packages/core/src/Dialog/__tests__/DialogSecondDocument.a11y.browser.spec.ts,]members:[@@ -86,6 +87,10 @@ deciding_specs: []A person dismissing layered UI should affect only the topmost relevant surface.A nested surface must not close its host on the same Escape press or platformclose request when logical depth or DOM containment establishes that ordering.+A trigger-anchored member rendered in a same-origin iframe or a+Picture-in-Picture window dismisses there and returns focus in the document it+was opened from, as it does in the page; BottomSheet, BottomSheetSwitcher and Lightbox do so in a+Picture-in-Picture window only, and Drawer and MobileNav stay in the page.## Membership rule@@ -127,8 +132,7 @@ this record's current membership snapshot must be updated with it.- `useLayerDismissal` registers an active surface and adapts abrowser-initiated close request to the shared topmost check.- `layerStack` owns presence filtering, ordering, and the document-level- Escape listener: one in each document that holds a registered member (FR8,- proposed; pending owner review).+ Escape listener: one in each document that holds a registered member (FR8).- `LayerDepthProvider` carries logical nesting through the React tree for membersthat provide it to their descendants. Members without that provider do notguarantee nested ordering after descendant content leaves DOM containment.@@ -174,23 +178,35 @@ this record's current membership snapshot must be updated with it.- **FR7 — Registration does not define open-state ownership.** The stack invokesthe selected member's dismissal callback. Whether that request immediatelycloses the surface is owned by the member's component contract and caller.-- **FR8 — Each document ranks its own members.** A member belongs to the- document of the element it registers with: Dialog (and CommandPalette through- it), Lightbox, MobileNav, BottomSheet, BottomSheetSwitcher and Drawer register- their dialog, ContextMenu its menu, and a focus trap its container. 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 members nested in it that register an element keep- one order wherever they render. A member of another document is never a- candidate. Tooltip and HoverCard register no element and read their presence- from the page's document: they belong to the page, and in another document- they take no request, so their host handles the first one. The stack listens- once in each document that holds a member and stops when its last member- leaves. Proposed; pending owner review (DEC-2).+- **FR8 — A member works in the document it renders in.** A member opens and+ takes Escape and platform close requests in the document of the element it+ registers with, which is where it renders: Dialog (and AlertDialog and+ CommandPalette through it), Lightbox, MobileNav, BottomSheet,+ BottomSheetSwitcher and Drawer register their dialog, ContextMenu its menu, and+ a focus trap its container. Trigger-anchored members, Dialog, Popover and+ every member built on it, DropdownMenu, ContextMenu, Tooltip and HoverCard,+ render in the page, a same-origin iframe, or a Document Picture-in-Picture+ window. BottomSheet, BottomSheetSwitcher and Lightbox cover the window they+ render in and work in the page and in a Picture-in-Picture window, not inside+ an embedded iframe. Drawer and MobileNav are page-level and work only in 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 members nested in it+ keep one order wherever they render. A member of another document is never a+ candidate. A Tooltip never wins or blocks an Escape press against another+ member (`spec:AST-003` FR4): Escape closes a Tooltip only when it is the only+ present member in its document. The stack listens once in each document that holds a+ member and stops when its last member leaves.+- **FR9 — Focus returns in the opener's document.** Closing a trigger-anchored+ member returns focus, when it would otherwise be lost, to the member's return+ target, in the opener's document, with the ring the last input in that+ document calls for (`architecture:interaction-modality` INV1); a BottomSheet,+ BottomSheetSwitcher, or Lightbox does the same in a Picture-in-Picture window.## Allowed component variation-- **AV1 — Focus.** Members own focus entry, containment, movement, and return.+- **AV1 — Focus.** Members own focus entry, containment, movement, and the+ return target. FR9 fixes the document focus returns in.- **AV2 — Modality.** Members may be modal or non-modal and own any inertness orbackdrop behavior.- **AV3 — Positioning and hosting.** Members may use native dialog placement,@@ -204,46 +220,57 @@ this record's current membership snapshot must be updated with it.## Representative matrix-| Member and state | Shared invariant | Deliberate variation |-| --------------------------------------------- | ---------------------------------------------- | ----------------------------------------------------------------------------- |-| 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 |-| Registered descendant inside CommandPalette | Descendant handles the first Escape | CommandPalette inherits Dialog's shared stack participation |-| 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 |-| Lightbox or MobileNav above a required Dialog | Top member handles the request | Required Dialog uses `block` only when it is topmost |-| Required Dialog alone | Request is consumed without closing | Dialog purpose selects `block` behavior |-| Self-owned input popup | Popup participates while present | Input owns selection, focus, open state, positioning, and outside dismissal |-| Two unrelated registered surfaces | Later active-cycle registration is topmost | Neither surface is treated as nested |-| 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) |+| Member and state | Shared invariant | Deliberate variation |+| ------------------------------------------------------ | ------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |+| 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 |+| Registered descendant inside CommandPalette | Descendant handles the first Escape | CommandPalette inherits Dialog's shared stack participation |+| Tooltip or HoverCard inside Dialog, in page | An open HoverCard handles the first Escape; over a Tooltip, the Dialog takes it | Hover families decide when they are present and how controlled state responds |+| Lightbox or MobileNav above a required Dialog | Top member handles the request | Required Dialog uses `block` only when it is topmost |+| Required Dialog alone | Request is consumed without closing | Dialog purpose selects `block` behavior |+| Self-owned input popup | Popup participates while present | Input owns selection, focus, open state, positioning, and outside dismissal |+| Two unrelated registered surfaces | Later active-cycle registration is topmost | Neither surface is treated as nested |+| 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 | An open HoverCard handles the first Escape there; over a Tooltip, the Dialog takes it | A Tooltip never wins or blocks Escape against another member (`spec:AST-003` FR4) |+| ContextMenu in a Picture-in-Picture window | Escape closes it; focus returns to its opener there | The menu opens where the person pressed (FR8, FR9) |+| BottomSheet or Lightbox in a Picture-in-Picture window | Escape closes it; focus returns to its return target there | The surface covers that window (FR8, FR9) |+| BottomSheet or Lightbox in an embedded iframe | Not supported | A surface that covers its window works only where the window is the app (FR8) |+| Drawer or MobileNav | Page only | Page-level surfaces stay in the page's document (FR8) |## Adoption and exceptions-| Components or surface | Adoption | Current deviation or limitation |-| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |-| Dialog, AlertDialog, Popover, DropdownMenu root, ContextMenu, MoreMenu, Lightbox, MobileNav, Drawer, CommandPalette | shared owner; CommandPalette composes Dialog | none |-| Tooltip, HoverCard | shared owner with DOM presence reporting | Neither provides nesting depth to descendant layers; both read presence from the page's document, so in another document they take no request (FR8) |-| Focus traps with `onEscape` | shared owner through `useFocusTrap` | They provide DOM containment, not descendant depth |-| BreadcrumbItem, ChatComposerInput, ComplexSelector, DateInput, DateRangeInput, DateTimeInput, Selector, MultiSelector, PowerSearch, BaseTypeahead, Typeahead, Tokenizer, SideNavHeading, SideNavItem, TabMenu, TopNavHeading, TopNavMenu, TopNavMegaMenu, Table, Lab TourStep, Lab ChatEmojiPicker | shared owner through `usePopover` or a composed Popover owner | Table filtering owns controlled Popover state and discards its draft on close; TourStep routes Popover close to the Tour; ChatEmojiPicker owns controlled Popover state |-| BottomSheet, BottomSheetSwitcher | shared owner | none |-| DropdownMenuSubMenu, PowerSearchEditPopover | local only | Must migrate from component-specific listeners or registries to the shared owner |--The rows marked partial or local are current adoption gaps against FR1. They are-not approved exceptions. Migration must preserve each component's existing focus,+| Components or surface | Adoption | Current deviation or limitation |+| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |+| Dialog, AlertDialog, Popover, MobileNav, Drawer, CommandPalette | shared owner; CommandPalette composes Dialog | none |+| Tooltip, HoverCard | shared owner with DOM presence reporting | Neither provides nesting depth to descendant layers. Implementation gap: a Tooltip consumes Escape when it is the topmost layer, so the layer beneath it stays open for that press, and a Tooltip in another document is never closed by Escape (`component:Tooltip` FR6); FR8 gives that press to the layer beneath and closes a lone Tooltip in its own document. HoverCard reads its presence from the page's document, so in another document it takes no request (FR8) and returns no focus there (FR9) |+| Focus traps with `onEscape` | shared owner through `useFocusTrap` | They provide DOM containment, not descendant depth |+| BreadcrumbItem, ChatComposerInput, ComplexSelector, DateInput, DateRangeInput, DateTimeInput, Selector, MultiSelector, PowerSearch, BaseTypeahead, Typeahead, Tokenizer, SideNavHeading, SideNavItem, TabMenu, TopNavHeading, TopNavMenu, TopNavMegaMenu, Table, Lab TourStep, Lab ChatEmojiPicker | shared owner through `usePopover` or a composed Popover owner | Table filtering owns controlled Popover state and discards its draft on close; TourStep routes Popover close to the Tour; ChatEmojiPicker owns controlled Popover state |+| DropdownMenu root, MoreMenu, ContextMenu, Selector, MultiSelector, TopNavHeading, TopNavMenu, TopNavMegaMenu, SideNavHeading, SideNavItem, BottomSheet, BottomSheetSwitcher, Lightbox | shared owner | Implementation gap: in another document (for BottomSheet, BottomSheetSwitcher and Lightbox, a Picture-in-Picture window), each decides focus return from the page's document and last input, so focus returns to the frame element or the page, or without the ring the last input in its document calls for (FR9) |+| DropdownMenuSubMenu, PowerSearchEditPopover | local only | Must migrate from component-specific listeners or registries to the shared owner |++The rows marked partial or local are current adoption gaps against FR1, and the+rows naming an implementation gap are gaps against FR8 or FR9. They are not+approved exceptions. The implementation gaps listed are the known ones, not a+full inventory: a member found deciding focus return or Escape from the page's+document is the same known gap. Migration must preserve each component's existing focus,modality, positioning, outside-dismissal, and open-state contracts.## Verification map-| Contract | Verification | Representative members and states | Mutation or failure expectation |-| ------------------ | --------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |-| FR1, FR2, FR4, FR5 | `useLayerDismissal.test.tsx`; `BottomSheetSwitcher.test.tsx`; `ContextMenu.test.tsx`; `CommandPalette.test.tsx` | synthetic provider depth, same-DOM containment, non-modal switcher nesting, ContextMenu nested layers, CommandPalette descendant nesting, unrelated, blocking, content-handled, present/absent | Removing depth, presence filtering, or event deferral sends Escape to the wrong surface |-| FR2, FR3, FR4, FR6 | `layerDismissalInvariants.test.tsx` | nested same-DOM Dialogs, Lightbox over Dialog, Dialog in BottomSheet, platform cancel, IME | One request closes two surfaces, closes a host before its child, or dismisses during composition |-| FR1, FR2, FR3, FR7 | `layerDismissalFamilies.test.tsx` | Dialog, Lightbox, MobileNav, BottomSheet, Tooltip, HoverCard; controlled and blocking states | A family bypasses the stack, a lower member handles a request, or controlled ownership is ignored |-| FR1 | `useFocusTrap.test.tsx` | active, nested, and deactivated traps with `onEscape` | A dismissible trap stays off the shared stack or nested traps respond together |-| FR8 | `useLayerDismissal.test.tsx`; `Popover.test.tsx` | members in the page and a same-origin iframe; a Popover alone and inside a Dialog, in an iframe | A press in one document dismisses a member of another, or a host closes over its nested layer |-| FR8 | `PopoverSecondDocument.a11y.chromium.spec.ts` | a Popover in an iframe and in a Picture-in-Picture window, alone and with one open in the page | A press in the second document misses its own layer or dismisses the page's |+| Contract | Verification | Representative members and states | Mutation or failure expectation |+| ------------------ | --------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------- |+| FR1, FR2, FR4, FR5 | `useLayerDismissal.test.tsx`; `BottomSheetSwitcher.test.tsx`; `ContextMenu.test.tsx`; `CommandPalette.test.tsx` | synthetic provider depth, same-DOM containment, non-modal switcher nesting, ContextMenu nested layers, CommandPalette descendant nesting, unrelated, blocking, content-handled, present/absent | Removing depth, presence filtering, or event deferral sends Escape to the wrong surface |+| FR2, FR3, FR4, FR6 | `layerDismissalInvariants.test.tsx` | nested same-DOM Dialogs, Lightbox over Dialog, Dialog in BottomSheet, platform cancel, IME | One request closes two surfaces, closes a host before its child, or dismisses during composition |+| FR1, FR2, FR3, FR7 | `layerDismissalFamilies.test.tsx` | Dialog, Lightbox, MobileNav, BottomSheet, Tooltip, HoverCard; controlled and blocking states | A family bypasses the stack, a lower member handles a request, or controlled ownership is ignored |+| FR1 | `useFocusTrap.test.tsx` | active, nested, and deactivated traps with `onEscape` | A dismissible trap stays off the shared stack or nested traps respond together |+| FR8 | `useLayerDismissal.test.tsx`; `Popover.test.tsx` | members in the page and a same-origin iframe; a Popover alone and inside a Dialog, in an iframe | A press in one document dismisses a member of another, or a host closes over its nested layer |+| FR8 | `PopoverSecondDocument.a11y.chromium.spec.ts` | a Popover in an iframe and in a Picture-in-Picture window, alone and with one open in the page | A press in the second document misses its own layer or dismisses the page's |+| FR9 | `DialogSecondDocument.a11y.browser.spec.ts` | a Dialog in an iframe and in a Picture-in-Picture window, closed by Escape or a control inside it, and a Dialog in an iframe opened from the page | Focus lands outside the opener's document, or its ring does not follow the closing input |+| FR8, FR9 | Real-browser second-document checks; implementation gap: only Dialog and Popover have them | Dialog, Popover, DropdownMenu, MoreMenu, ContextMenu, Selector, MultiSelector, TopNavHeading, TopNavMenu, TopNavMegaMenu, SideNavHeading, SideNavItem, Tooltip and HoverCard, each in a same-origin iframe and in a Picture-in-Picture window: opens and takes Escape in the document it renders in (a Tooltip only when no other member is present), and returns focus in the opener's document | The member opens or ranks in another document, or focus lands on the frame element, the page, or the body |+| FR8, FR9 | Real-browser second-document checks; implementation gap: none has them | BottomSheet, BottomSheetSwitcher, and Lightbox in a Picture-in-Picture window: opens, takes Escape, and returns focus to its return target there | The surface ranks in the page, or focus lands on the page or the body |+| FR8 | Source check over Drawer and MobileNav | Drawer and MobileNav rendered from a control in a second document | A page-level surface moves into the second document |## Decision links@@ -263,22 +290,28 @@ are the audited current snapshot, not a closed set.A layer with no dismissal behavior does not participate. A visual-only outlinerendered through Layer is the canonical nonparticipating example.-### DEC-2 — Each document ranks its own members+### DEC-2 — Each surface works in the document it belongs to-**Decider:** pending owner review+**Decider:** `cixzhang`, `2026-10-31`A key press and a platform close request reach only the document they happen-in, and each document keeps its own browser top layer. The stack therefore-orders the members of each document separately and listens once per document.-One request still affects exactly one surface: the topmost one in the document+in, and each document keeps its own browser top layer and its own focus. A+member therefore opens and ranks in the document it renders in, and returns+focus in its opener's document. A trigger-anchored member renders in the page, a+same-origin iframe, or a Picture-in-Picture window. A surface that covers its+window, BottomSheet, BottomSheetSwitcher or Lightbox, works where the window is+the app: the page or a Picture-in-Picture+window, not an embedded iframe. Page-level surfaces stay in the page. One+request still affects exactly one surface: the topmost one in the documentwhere the person acted.Rejected: one order across documents, where a press in one window dismisses a surface in another.## Open questions-None. Focus, modality, positioning, outside dismissal, and open-state APIs are-explicitly outside this family contract. The mapped tests do not render a nested+None. Focus entry, containment, movement, and the return target, modality,+positioning, outside dismissal, and open-state APIs are outside this family+contract; FR9 fixes only the document focus returns in. The mapped tests do not render a nestedlayer through a real portal; a real portal fixture is required before thiscontract can claim verified portal coverage.@@ -288,7 +321,9 @@ This file owns family membership, topmost registered Escape and platform-closebehavior, and the logical-depth and DOM-containment signals currently used toorder those requests. A member guarantees descendant depth only when it provides`LayerDepthProvider`; this record does not claim verified nesting through a real-portal. It does not define focus entry or return, modality, positioning or+portal. It owns the document a member opens, dismisses, and returns focus in+(FR8, FR9). It does not define focus entry, containment, movement, or the return+target, modality, positioning oranchoring, portal placement, outside interaction, programmatic componentcommands, open-state APIs, animation, or theming. Those remain component,family, or architecture responsibilities.