/** * Overlay layer stack, modal focus handling and body scroll lock, shared by * every component that floats above the page and closes on Escape. * * ## Why this exists (#332) * * Each overlay used to listen for Escape on `window` by itself. All of those * listeners run for the same key press, so a popover inside a dialog closed * together with the dialog, and `stopPropagation()` in one handler did not stop * the others. Sheet and drawer also rendered `aria-modal="true"` without any * of the modal behaviour dialog had (focus moved in, Tab trapped, focus * restored, page scroll locked). * * ## Model (matches Radix DismissableLayer / FocusScope) * * - Every open overlay is an {@link OverlayLayer} on one document-wide stack, * in the order the layers opened. * - One pair of `window` keydown listeners handles Escape: the layer that was * on top when the key went down gets the key, nothing below it does. If an * element-level handler inside that layer already closed it (a combobox input * closing its list, a submenu calling `stopPropagation()`), the key is spent * and no other layer closes. * - The topmost *modal* layer traps Tab inside its container. Modal layers * also move focus in when they open, return it to the element that had it * when they close, and lock body scroll. The lock is reference-counted, so a * dialog closing inside an open sheet leaves the page locked. */ /** * Lock body scroll. Safe to nest: the lock is applied on the first call and * the original inline styles come back on the matching last unlock. */ export declare function lockBodyScroll(): void; /** Release one lock taken with lockBodyScroll(). */ export declare function unlockBodyScroll(): void; export interface OverlayLayerOptions { /** * Called when Escape is pressed while this layer is the topmost one. The * handler decides whether to close (e.g. `closeOnEscape`); either way the * key does not reach the layers below. */ onEscape?: (event: KeyboardEvent) => void; /** * Modal layers trap Tab inside `container`, move focus into it on open, * restore focus on close and lock body scroll. A function is read on every * activation (dialog's `modal` prop can change). */ modal?: boolean | (() => boolean); /** The element focus is moved into and trapped in (modal layers). */ container?: () => HTMLElement | null | undefined; } /** * One overlay's place on the layer stack. * * private layer = new OverlayLayer({ onEscape: () => this.close() }); * componentDidRender() { this.layer.setActive(this._isOpen); } * disconnectedCallback() { this.layer.setActive(false); } * * Modal content parts call `setActive()` from the code path that sees the * open state change (so focus is captured before anything moves it) and * `didRender()` from componentDidRender, which moves focus in once the * container exists. */ export declare class OverlayLayer { private readonly options; private active; private modalActive; private returnFocusTo; private focusPending; constructor(options?: OverlayLayerOptions); get isActive(): boolean; /** Whether this layer is open and modal (traps focus, locks scroll). */ get isModal(): boolean; /** Activate or deactivate; idempotent, so it can be called on every render. */ setActive(active: boolean): void; activate(): void; deactivate(): void; /** Move focus into a modal layer once its container has rendered. */ didRender(): void; handleEscape(event: KeyboardEvent): void; handleTab(event: KeyboardEvent): void; private restoreFocus; } /** * Title and description text for a dialog-like content part. * * The `role="dialog"` element lives in the content part's shadow root, while * the title and description are separate custom elements in the light DOM. An * `aria-labelledby` id reference cannot cross that shadow boundary, so the * dialog had no accessible name or description. ARIA element reflection * (`ariaLabelledByElements`) can reach outward, but test tooling and older * engines don't follow it, so the content part mirrors the text into hidden * elements in its own shadow root and references those instead (the approach * `label-association.ts` takes for labels). A MutationObserver keeps the copy * in sync while the content is open. * * Only the title/description that belong to this content part count, not * those of an overlay nested inside it. */ export declare class DialogLabelSource { private readonly onChange; private observer?; private host; constructor(onChange: (label: string, description: string) => void); private find; private sync; /** Start tracking the content part `host` (call when it opens). */ observe(host: HTMLElement): void; disconnect(): void; }