Overlay and disclosure machines
Overlay and disclosure machines coordinate UI that opens above or beside the page, then closes without losing the user's place. They share contracts for open state, trigger ownership, outside dismissal, focus, placement, and layered rendering, while adapting those contracts for modal dialogs, anchored hints, notifications, movable panels, and guided tours.
Overlay families
The component machines form a small set of behavior families rather than one generic overlay. Each family chooses a different source of truth for opening and a different way to preserve context around the overlay.
| Family | Main purpose | Open and close model | Position or layer model |
|---|---|---|---|
| Dialog and drawer | Modal or non-modal task surface | Trigger, close control, Escape, and outside interaction | Centered or edge-attached surface; drawer adds swipe and snap states |
| Popover | User-controlled anchored content | Trigger toggle, outside interaction, and Escape | Placement relative to an anchor or trigger |
| Tooltip and hover card | Short context shown from hover or focus | Delay-based pointer and focus transitions | Placement relative to the active trigger |
| Toast | Status or action feedback | Timer, pause, or explicit dismiss | Fixed notification region with stack or overlap behavior |
| Floating panel | Persistent workspace surface | Trigger, close control, and Escape | User-controlled position and size inside a boundary |
| Tour | Step-by-step product guidance | Start, next, previous, skip, and dismiss | Spotlight or dialog step tied to a target |
The machines expose their state through framework-neutral connect APIs. Framework packages render the returned trigger, content, positioner, and control props, and portal the parts that need a different DOM location; see Framework integrations.
References: packages/…/dialog.machine.ts• L10-31 packages/…/drawer.machine.ts• L39-63 packages/…/popover.machine.ts• L11-25 packages/…/tooltip.machine.ts• L12-37 packages/…/hover-card.machine.ts• L9-20 packages/…/toast.machine.ts• L10-23 packages/…/floating-panel.machine.ts• L35-51 packages/…/tour.machine.ts• L23-38
Open state and trigger ownership
Open state is a two-way contract between a machine and its consumer. A machine can own the state from defaultOpen, or it can report requested changes through onOpenChange while the consumer owns the open value. This lets the same trigger API support both local use and state held by a route, store, or application flow.
The trigger also records which trigger value opened the surface when one machine serves several triggers. On close, the machine uses that value to restore focus to the active trigger instead of an unrelated trigger from the same group.
sequenceDiagram
participant U as User
participant T as Trigger
participant M as Machine
participant C as Consumer state
participant O as Overlay
U->>T: activate or focus
T->>M: OPEN or TOGGLE with trigger value
M->>C: onOpenChange(open: true) when controlled
C->>M: open = true when controlled
M->>O: publish open, trigger, and accessibility props
U->>O: close control, Escape, or outside interaction
O->>M: CLOSE
M->>C: onOpenChange(open: false) when controlled
M->>T: restore focus to active trigger when enabled
Dialog, drawer, popover, hover card, and floating panel use this open contract directly. Tooltip adds focus and pointer timing, toast uses a notification status rather than a trigger-owned open flag, and tour uses a running step sequence rather than a simple boolean.
References: packages/…/dialog.machine.ts• L28-49 packages/…/dialog.connect.ts• L18-49 packages/…/popover.machine.ts• L28-51 packages/…/hover-card.machine.ts• L23-49 packages/…/floating-panel.machine.ts• L48-102 packages/…/dialog.machine.ts• L164-195
Trigger interfaces
Trigger interfaces connect user intent to the machine and publish the state needed by assistive technology and styles. They identify the controlled content, expose expanded state, and carry the active trigger value when several triggers share one machine.
- Dialog, drawer, and popover use a button-like trigger that toggles or switches the active value.
- Tooltip opens from focus or pointer movement and closes from blur, pointer leave, click, or pointer down according to its settings.
- Hover card keeps a delayed open window while focus or pointer presence remains on the trigger or content.
- Floating panel uses a trigger to open or close the panel, then uses content focus to bring the panel to the front.
- Tour starts from an imperative action and then exposes step actions instead of a normal trigger.
References: packages/…/dialog.connect.ts• L29-49 packages/…/drawer.connect.ts• L193-218 packages/…/popover.connect.ts• L68-101 packages/…/tooltip.connect.ts• L48-118 packages/…/hover-card.connect.ts• L52-93 packages/…/floating-panel.connect.ts• L77-93 packages/…/tour.connect.ts• L97-113
Dismissal and focus behavior
Dismissal is part of the machine's life cycle, not only a click handler. Overlay machines watch for Escape, outside pointer or focus activity, and explicit close actions. They can prevent a dismissal through their public settings or event callbacks, which allows nested surfaces and application-owned close rules to remain open.
Modal surfaces add stronger browser coordination. Dialog, drawer, and modal popover can block page scroll, hide content below the surface from assistive technology, and keep focus inside the active content. Non-modal popovers use focus handoff instead of a focus trap when their content is portalled, so keyboard navigation still returns to the trigger's place in the page.
The shared focus and dismissal utilities define the browser rules used by these machines. Read Focus, dismissal, and positioning utilities for the lower-level behavior and edge cases.
| Surface | Focus on open | Focus on close | Outside and Escape behavior |
|---|---|---|---|
| Dialog and modal drawer | Initial focus or close control for alert roles | Active trigger or final focus element | Dismissible outside by default unless configured otherwise; Escape is configurable |
| Modal popover | Initial focus when enabled | Active trigger or final focus element | Outside and Escape close by default |
| Non-modal popover | Optional initial focus | Trigger when restoration is enabled | Outside and Escape close by default; tab order is proxied when portalled |
| Hover card | Does not trap focus; outside focus is kept outside the card | Delay-based close | Outside focus is prevented from closing through the card's focus policy |
| Tooltip | Opens on visible focus; no focus trap | Closes on blur or pointer leave | Escape, scroll, pointer lock, and configured pointer actions can close it |
| Toast | Region can receive focus; focus and pointer entry pause timers | Previously focused element can be restored | Escape and explicit dismiss remove the toast; the group is a dismissable branch |
| Floating panel | Initial focus or panel content | Trigger or final focus element | Topmost panel handles Escape; focus brings a panel to the front |
| Tour | Focus trap includes tour content and the highlighted target | The tour does not force normal dialog return focus | Escape, outside interaction, skip, and dismiss end or advance the tour |
References: packages/…/dialog.machine.ts• L57-74 packages/…/dialog.machine.ts• L128-202 packages/…/popover.machine.ts• L102-124 packages/…/popover.machine.ts• L162-245 packages/…/hover-card.machine.ts• L154-284 packages/…/tooltip.machine.ts• L166-227 packages/…/toast-group.machine.ts• L67-85 packages/…/floating-panel.machine.ts• L174-219 packages/…/tour.machine.ts• L230-263
Anchored positioning and portals
Anchored overlays separate the trigger or anchor from the visible content. The machine tracks a current placement and asks the positioning system to update the positioner when the trigger, placement options, or active trigger value changes. The connect API then publishes placement styles and side data for the positioner, arrow, trigger, and content.
Popover, tooltip, and hover card follow this pattern. Tour tooltip steps use the same placement idea after they resolve a target, while dialog and drawer use a positioner as a layer wrapper rather than an anchor-relative placement surface.
Portal behavior changes the DOM relationship but not the interaction relationship. Popover reports whether content should be portalled, and its non-modal portalled mode proxies tab focus so the user does not jump to the end of the document. Modal focus traps and dismissable branches also account for related portalled content. The framework adapter supplies the actual portal operation; the machine supplies the behavior contract.
flowchart LR
A[Trigger or anchor] --> M[Overlay machine]
M --> P[Placement service]
P --> R[Positioner props and styles]
R --> C[Overlay content]
M --> D[Dismissal and focus rules]
D --> T[Trigger or final focus]
C -->|render in place or portal| DOM[Framework DOM tree]
References: packages/…/popover.machine.ts• L54-62 packages/…/popover.machine.ts• L147-160 packages/…/popover.machine.ts• L193-210 packages/…/popover.connect.ts• L18-41 packages/…/tooltip.machine.ts• L365-383 packages/…/tooltip.connect.ts• L28-45 packages/…/hover-card.machine.ts• L254-284 packages/…/tour.machine.ts• L536-595 packages/…/portal.tsx• L1-22
Layered surfaces
Some surfaces need more than one open overlay to share space safely. Drawer instances publish their open, height, and swipe state so nested drawers can indent behind the frontmost drawer. Floating panels publish stack order so the active panel renders above its siblings and receives Escape. Toast groups use placement regions to stack or overlap notifications, pause them on hover or focus, and mark the region as a branch that does not dismiss other layers.
These layer contracts keep visual order and interaction order aligned. A front surface must be the one that receives keyboard dismissal and focus, while a background surface must remain visible only when its family permits it.
References: packages/…/drawer.stack.ts• L5-35 packages/…/drawer.machine.ts• L195-200 packages/…/floating-panel.machine.ts• L132-177 packages/…/floating-panel.machine.ts• L347-357 packages/…/floating-panel.connect.ts• L29-47 packages/…/toast-group.machine.ts• L94-136 packages/…/toast-group.machine.ts• L183-203
Component-specific state machines
The shared overlay contract gives the components a common mental model, but each machine adds state that matches its product role. The important differences are the states that can delay visibility, change placement, or change how dismissal affects the rest of the page.
Dialog and drawer states
Dialog is a two-state surface with modal defaults. Drawer follows the same modal contract but adds a closing phase, snap points, nested-drawer coordination, and swipe-open or swipe-close behavior. Its open state therefore remains visible while a close animation or drag decision completes.
References: packages/…/dialog.machine.ts• L57-121 packages/…/drawer.machine.ts• L214-420 packages/…/drawer.connect.ts• L20-55
Popover states
Popover is an anchored open or closed surface. Its key choice is modal versus non-modal behavior: modal mode adds the page-level protections, while non-modal mode keeps the page usable and can preserve tab order across a portal.
References: packages/…/popover.machine.ts• L72-141 packages/…/popover.machine.ts• L162-245 packages/…/popover.types.ts• L55-102
Tooltip and hover card states
Tooltip and hover card model visibility as a timed relationship between trigger and content. Tooltip also coordinates a shared visible tooltip so pointer movement can switch between related triggers without showing several tooltips at once. Hover card keeps content open while the pointer crosses from trigger to content and closes after a separate delay.
References: packages/…/tooltip.machine.ts• L77-270 packages/…/tooltip.machine.ts• L273-455 packages/…/hover-card.machine.ts• L70-228 packages/…/hover-card.machine.ts• L237-284
Toast states
Toast has a visible life cycle instead of an open life cycle. A normal toast counts down, pauses when the group gains focus or pointer presence, enters a dismissing phase, and stays mounted for its removal delay so the group can animate and then remove it. Loading and infinite-duration toasts persist until an explicit dismiss.
References: packages/…/toast.machine.ts• L20-23 packages/…/toast.machine.ts• L108-161 packages/…/toast.machine.ts• L163-209 packages/…/toast-group.machine.ts• L111-134
Floating panel states
Floating panel has an open or closed state with nested idle, dragging, and resizing states. It keeps position and size as user-facing state, constrains them to a boundary, and supports minimized, maximized, and restored stages. The panel stack makes the focused panel topmost.
References: packages/…/floating-panel.machine.ts• L105-144 packages/…/floating-panel.machine.ts• L146-268 packages/…/floating-panel.connect.ts• L29-75
Tour states
Tour starts inactive and then routes each step through target resolution, scrolling, waiting, or active display. A step can point to a target for a spotlight, act as a dialog step, wait for an effect, or fail when its target does not appear before the timeout. Step changes clean up the old target and placement before the next step becomes active.
References: packages/…/tour.machine.ts• L36-114 packages/…/tour.machine.ts• L172-264 packages/…/tour.machine.ts• L393-595
Change checklist
When these files or sections are changed, remember to consider these:
- Keep
openor equivalent status changes aligned with the controlled-state callback contract. A consumer that owns the value must receive the request before the rendered state can change. - Keep trigger-value changes aligned with active-trigger lookup and focus restoration. Multi-trigger surfaces can silently restore focus to the wrong control if IDs or value routing change.
- Keep positioner, content, arrow, and trigger placement data in sync when placement updates or a portal changes where content is mounted.
- Keep modal settings aligned across outside dismissal, Escape handling, focus trapping, scroll lock, and aria hiding. Changing one default can leave the other protections inconsistent.
- Keep delayed states and exit or removal timing aligned with mounted content. Tooltip, hover card, drawer, and toast transitions can otherwise close before their cleanup or animation path runs.
- Keep shared layer registration aligned with the rendered stack. Nested drawers, floating panels, toast regions, and tours depend on the frontmost surface being the one that receives focus or dismissal.
- When changing tour step routing, preserve target cleanup, spotlight geometry, and the status callbacks for start, dismiss, skip, completion, and missing targets.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A controlled overlay receives an open or close request but the consumer does not update its value | The callback reports the request while the machine remains out of sync with the rendered content | Treat onOpenChange as a request contract and return the new open value from the consumer |
| A portalled non-modal popover skips its tab-focus proxy | Keyboard focus can jump past the content or leave the trigger and content in the wrong order | Keep portalled state and proxy-tab behavior coupled |
| A modal surface omits one of outside tracking, focus trapping, scroll lock, or aria hiding | Pointer, keyboard, scroll, or screen-reader access can reach the page behind the surface | Review the full modal behavior set together |
| A trigger value changes without repositioning or active-trigger lookup | Content can stay beside the old trigger and focus can return to the wrong trigger | Route trigger-value changes through positioning and focus ownership |
| A tooltip or hover card closes as soon as the pointer crosses into content | Interactive or delayed content becomes unreachable | Keep trigger and content pointer transitions under the same delay state |
| A drawer stack or panel stack has stale registration | A background surface can receive Escape or appear above the active surface | Register on open and remove on close or service cleanup |
| A toast is removed before its removal delay ends | Exit animation and height-based stack layout can jump or leave stale spacing | Separate dismissing from unmounted and update group height state at removal |
| A tour target disappears during a step | Spotlight and content can point at stale geometry | Re-resolve the target, clean the old target attributes, and report a not-found step when resolution times out |
Key files
| File | Why to read it |
|---|---|
| packages/…/dialog.machine.ts | Core modal open, dismissal, focus, scroll, and aria behavior |
| packages/…/dialog.connect.ts | Public trigger, content, backdrop, and close contracts |
| packages/…/drawer.machine.ts | Dialog-like behavior extended with swipe, snap, exit, and nested state |
| packages/…/drawer.stack.ts | Shared nested-drawer layer and swipe snapshot |
| packages/…/popover.machine.ts | Anchored modal and non-modal overlay behavior, including portals |
| packages/…/popover.connect.ts | Placement, trigger, positioner, and content props |
| packages/…/tooltip.machine.ts | Delay, shared visibility, focus, pointer, scroll, and placement flow |
| packages/…/hover-card.machine.ts | Delayed trigger-to-content hover relationship |
| packages/…/toast.machine.ts | Timed visible, paused, dismissing, and unmounted life cycle |
| packages/…/toast-group.machine.ts | Notification region stacking, pausing, focus, and dismissable-branch behavior |
| packages/…/floating-panel.machine.ts | Movable, resizable, staged, bounded, and stacked panel behavior |
| packages/…/tour.machine.ts | Target resolution, step routing, spotlight placement, and dismissal |
| packages/…/tour.connect.ts | Tour backdrop, spotlight, positioner, content, and step action contract |
| packages/…/focus-trap.ts | Focus containment and portalled controlled-element support |
| packages/…/portal.tsx | Example of the framework-level portal boundary used by rendered components |
Cross-links: Interactive component machines, Focus, dismissal, and positioning utilities, Framework integrations