Outline Morph
A trigger's focus ring grows into its popup's frame as the popup opens, and shrinks back onto the ring as it closes. It is on by default in every component where a focusable trigger opens a framed surface: an anchored popup, a dialog or a drawer's sheet. The rule is simple: an overlay morphs from the control that opened it, or it appears at once.
import {
OutlineMorphFrame,
OutlineMorphLayer,
OutlineMorphTail,
useOutlineMorph,
} from '@fairgarden/design/foundations/outline-morph'
The components below wire it for you, so most apps never import it. Build on it only for a popup of your own.
Where it runs
- Select: the trigger's ring or field edge grows into the list.
- Combobox, Autocomplete and Search (the boxed, ruled and docked fields): the box's ring, which shows on any focus, grows into the suggestions. It stays drawn while you type, since focus never leaves the input.
- Menu:
MenuTrigger's ring, or its outline, fill or box, grows into the popup. Every menu built on Menu takes it too: the Menubar's menus, the Toolbar's "…" overflow, the Breadcrumb's "…" and the Code Block's hanging ⋮, whose ear grows into the menu. - Popover: a panel or a definition. Its tail, if it has one, grows out of the frame's edge as the panel lands.
- Section Bar: the Jump to panel.
- Table of Contents: the contents bar's panel.
- Dialog and Alert Dialog: the trigger's ring or edge grows into the panel, or into the full-screen sheet on phones. An Alert Dialog opened from inside a Dialog grows from its trigger there.
- Nav Drawer and the docs drawer: the menu Button's ring grows into the side sheet, or into the full sheet on phones, whose close control sits where the menu Button was.
How the morph works
Across components
Opened from the keyboard, the morph starts on the ring the trigger draws. Opened by pointer, where no ring shows, it starts on the trigger's edge: a boxed trigger's edge in its own color, a solid Button's box in its fill, and, for a trigger with no edge of its own (a text Button, a bare glyph, a menubar item), the box its ring would draw, in its ink, so a pointer open and a keyboard open start and land on the same box. A frame grows from there to the popup's frame (--border-size-2 --primary12 on the anchored popups), changing radius and color on the way, and the popup's contents are revealed inside it by a clip on the same timing. Nothing fades, and the edge stays crisp in every frame: the frame moves and resizes in whole pixels and never scales. Where the start and the popup differ in weight, such as a 1 px field edge into a 2 px list, the weight steps once, 15% of the way along the eased travel while the frame moves fastest, and never passes through a fraction. When it lands, the frame hands off to the popup's own border in the same frame, so nothing changes on screen.
The close runs the other way and lands where focus ends up: on the ring when focus comes back with one, which the trigger then draws in the frame the overlay goes, and on the edge otherwise, as after an outside press.
Opening takes --fgd-duration-expand (333 ms) on --fgd-ease-expand; closing takes --fgd-duration-collapse (200 ms) on the same curve. The morph reads these tokens from the trigger at each open and close, so an app's override reaches it, and a duration of 0ms turns it off. A morph reversed midway turns where it is and runs the share left, never less than 35%. The end it travels to is measured again every frame, so a popup that flips above its trigger, a scroll, a resize or a list that settles its size bends the path instead of leaving the frame behind. The frame is out of flow, so it never moves the page.
Under reduced motion, in forced colors and in print the morph never runs, and the popup opens and closes at once; popups have no reveal of their own. While an open waits a frame for the popup's placement, the popup is held clipped away (it still takes focus), so it never shows before the morph starts. The trigger's resting, hover and focus styles are unchanged; the frame is an overlay on top of them.
Dialogs and sheets
A dialog or a drawer's sheet has no positioner, so its frame sits in a fixed layer the size of the viewport, drawn above the panel. These surfaces travel further, so they take their own pair of tokens: --fgd-duration-expand-surface (400 ms) to open and --fgd-duration-collapse-surface (240 ms) to close, on the same curve. The panel's 3 px frame is heavier than the 2 px ring, so the frame steps from 2 to 3 px early in the open, and back early in the close.
A sheet has no edge where it meets the viewport. There the frame lands one weight past the viewport's edge, so the edge leaves the screen instead of vanishing: the side sheet's frame ends on its 3 px inner edge, and a full-screen sheet's frame ends just outside all four edges. The close starts from there and lands on the ring focus returns to.
A dialog with no trigger to grow from opens and closes at once: an Alert Dialog opened from a Menu item, a dialog whose trigger has left the page, or one opened through a detached handle trigger. So does a Dialog with the solid cover from 768 px, because the cover hides the trigger in the first frame. The Search Dialog keeps its own expanding morph (Expanding Box).
Tails
A popup with a tail, such as a Popover with PopoverArrow, keeps it while it morphs. A copy of the tail sits above the growing frame and shows only on the trigger's side of the frame's edge, so as the edge travels toward the popup the tail grows out of it, tip first and always attached, and it is whole exactly as the frame lands. The popup's own tail takes over on the same pixels. On close it retracts into the edge as the edge leaves. It is a clip, so nothing fades.
Typing
Combobox, Autocomplete and Search open as you type, so the morph follows a typing policy:
- Explicit opens morph: a click in the field, the chevron, the arrow keys.
- The first open of a focus session morphs, even when typing caused it.
- After that, typing is instant: opens and closes that typing causes skip the morph and happen at once, so the list keeps up with the keys.
- Closes you ask for morph back onto the ring: Escape, a choice, an outside press.
- Filtering doesn't morph: an open popup that grows or shrinks as results change resizes on its own.
The morph never touches the input, so typing is never delayed or dropped while it runs.
Turning it off
Each adopting component takes morph={false}, which opens and closes the popup at once: Select, Combobox, Autocomplete, Search, Menu, Menubar (for all its menus, or one MenubarMenu), Popover, ToolbarMore, Breadcrumb, Section Bar, the Table of Contents bar, Dialog, Alert Dialog and Nav Drawer (and the docs drawer, which passes it on). The Search Dialog takes it too, for its own expanding morph.
To turn it off everywhere, or for part of a page, set --fgd-outline-morph: none. The morph reads it on the trigger and on the popup at every open and close, and it inherits, so :root covers the whole app. The Search Dialog's expanding morph honours it too. Setting the duration tokens to 0ms does the same; the dialogs and sheets read the surface pair. A component without a morph prop, such as the Code Block, takes it through its className or any ancestor.
:root {
--fgd-outline-morph: none;
}
Turning it off
The Select takes morph={false}; the Menu sits in a region that sets --fgd-outline-morph: none. Both open and close at once.
Where it doesn't run
- Tooltip and Preview Card: they open on hover as the pointer passes, like hints, so a morph would be noise; they appear at once. A Preview Card's trigger is also an inline link, which can wrap across lines.
- Context Menu: its trigger is a region with no outline, and the menu opens at the pointer, at once.
- Navigation Menu panels: a panel meets the bar's rule with no top edge, and the overview spans the viewport, so the frame could not hand off to them. They open on hover intent, at once, and switch instantly between neighbours.
- Toasts: no control opens them; they enter from their viewport edge.
- Dialogs with no trigger, or over the solid cover: they open and close at once (see Dialogs and sheets).
- Submenus: they open as the pointer passes over their row, at once, and the row has no outline to grow from.
- Hover opens and menubar switches: a Menu or Popover opened on hover appears at once, and moving between a Menubar's open menus stays instant.
Build your own
useOutlineMorph({ open }) returns stable refs. Put sourceRef on the trigger and targetRef on the popup. Put frameRef on an OutlineMorphFrame rendered as the popup's sibling inside the element that positions it, such as Base UI's Positioner, so the frame is out of flow and moves with the popup. Pass the popup's open state as the root has it after each commit. For a field whose ring shows on any focus, pass ring: 'focus-within'.
While the frame draws, the popup carries data-outline-morph. The popup's CSS must answer it: its border takes the face color, since the frame draws the edge, and its own transition steps aside.
.popup[data-outline-morph] {
border-color: var(--primary1);
transition: none;
}
For a surface with no positioner, such as a dialog, render the OutlineMorphFrame inside an OutlineMorphLayer after the popup in its portal, and pass surface: true for the surface durations. Each side of the popup without a border of its own must meet the viewport's edge, or the morph doesn't run.
For a tail, put tailSourceRef on the popup's own tail element and tailRef on an OutlineMorphTail rendered after the frame, holding the same drawing. The engine places the cap on the tail and copies its data-side, so rotate the cap as you rotate the tail. Draw its stroke in currentColor and fill it with var(--fgd-outline-morph-tail-fill), and hide the popup's own tail while data-outline-morph is set.
API Reference
useOutlineMorph
Grows a trigger’s focus ring into its popup’s frame on open, and back on close. With a ring drawn (keyboard focus, or any focus in a field), the morph starts on it; without one (a pointer press), on the trigger’s edge: its boxed edge, else its box in its fill, else (a text button, an underline, a bare glyph) its ring’s box in its ink. The close lands on the ring when focus stays or returns with one (the trigger’s own ring then shows in the same frame the overlay goes), else on the edge.
Wire three refs: sourceRef on the trigger (several triggers may share
one popup; the one marked open is used), targetRef on the popup,
and frameRef on an OutlineMorphFrame rendered as the popup’s sibling
inside the element that positions it (e.g. Base UI’s Positioner), so the
frame is out of flow and moves with the popup. The popup’s CSS must
answer [data-outline-morph]: its border takes its face color and its
own enter and exit transition is dropped.
| Property | Type | Description |
|---|---|---|
open | | The popup’s open state, as its root has it after each commit. |
enabled | | Run the morph. Default |
ring | | How the trigger draws its focus ring. Default |
duration | | Durations in ms, overriding the tokens. Default: the trigger’s
|
surface | | A modal surface (a dialog, a sheet), whose frame sits in an
|
OutlineMorphFrame, OutlineMorphTail, OutlineMorphLayer and canOutlineMorph
The overlay the morph animates: an empty 2 px frame (the popup’s own
weight and color, read at run time), absolutely positioned, hidden
unless a morph runs, aria-hidden and never hit-tested.
| Prop | Type | Description |
|---|---|---|
className | | Extra class names, added after the module’s own. |
The tail cap [§9.17]: the overlay’s copy of a popup’s tail, rendered
after OutlineMorphFrame in the same container so it paints above the
frame. While the morph runs it sits on the popup’s own tail (hidden
meanwhile) and shows only on the trigger side of the frame’s trigger-
facing edge, so the tail grows out of that edge as the frame arrives and
is whole as it lands. Its stroke is currentColor (the frame’s color on
the same timing); its face is --fgd-outline-morph-tail-fill (the
popup’s). Hidden unless a morph runs, aria-hidden, never hit-tested. A
popup without a tail never shows it.
| Prop | Type | Description |
|---|---|---|
children | | The same drawing as the popup’s tail (e.g. |
className | | The adopter’s class: the tail’s size, and its rotation per |
The container a modal surface’s frame sits in, since the surface has no
positioner: fixed, the full viewport, above the surface (--layer-4, the
dialogs’ layer, rendered after the popup in its portal) and never hit
tested, so the engine measures in viewport coordinates as they are.
| Prop | Type | Description |
|---|---|---|
children | | The |
className | | Extra class names, added after the module’s own (e.g. a |
Whether the morph may run now: Web Animations, motion allowed, no forced colors, not printing. Read at each open, so a preference change applies to the next one.
booleanAdditional types
OUTLINE_MORPH_ATTRIBUTE
The attribute the popup carries while the overlay draws its frame.
type OUTLINE_MORPH_ATTRIBUTE = 'data-outline-morph'OUTLINE_MORPH_PENDING_ATTRIBUTE
The popup’s attribute while an open waits for its placement (a frame or two, at most PLACEMENT_FRAMES): the foundation’s CSS holds the popup clipped away meanwhile (still focusable, as Base UI moves focus in during the wait), a discrete hold, so it never paints unclipped before the morph starts [D196]. A timeout removes it and the popup shows at once.
type OUTLINE_MORPH_PENDING_ATTRIBUTE = 'data-outline-morph-pending'OUTLINE_MORPH_PROPERTY
The app-wide (and per-subtree) switch: none on the trigger or the popup
(inherited, so :root turns every morph off) leaves every popup its own
open and close. Read at each open and close.
type OUTLINE_MORPH_PROPERTY = '--fgd-outline-morph'OutlineMorphDuration
Durations in ms: open grows the outline into the frame, close is the faster way back.
type OutlineMorphDuration = { open: number; close: number }OutlineMorphFrameProps
Props for OutlineMorphFrame.
type OutlineMorphFrameProps = {
/** `frameRef` from `useOutlineMorph`. */
ref: (element: HTMLElement | null) => void;
/** Extra class names, added after the module's own. */
className?: string;
}OutlineMorphLayerProps
Props for OutlineMorphLayer.
type OutlineMorphLayerProps = {
/** Extra class names, added after the module's own (e.g. a `z-index` other than the modal layer's). */
className?: string;
/** The `OutlineMorphFrame`. */
children?: React.ReactNode;
}OutlineMorphRefs
The refs useOutlineMorph returns: stable callbacks for the three elements.
type OutlineMorphRefs = {
/** A trigger: its focus ring (or edge) is where the morph starts and lands. */
sourceRef: (element: HTMLElement | null) => void;
/** The popup: its border box and radius are the frame the morph grows into. */
targetRef: (element: HTMLElement | null) => void;
/** The overlay: pass to `OutlineMorphFrame`. */
frameRef: (element: HTMLElement | null) => void;
/** The popup's own tail, if it has one (an arrow): the cap copies it while the morph runs. */
tailSourceRef: (element: HTMLElement | null) => void;
/** The tail cap: pass to `OutlineMorphTail`, rendered after the frame. */
tailRef: (element: HTMLElement | null) => void;
}OutlineMorphRing
How the trigger draws its focus ring, so the engine knows when it shows:
focus-visible: on the trigger itself while it matches:focus-visible(buttons, menu triggers, the Select trigger). Focus moves into the popup while it is open and comes back on close.focus-within: on the trigger (a field’s box) whenever anything inside it holds focus, pointer focus included (Combobox, Autocomplete, Search::has(:focus)ordata-focused). Focus stays in the input while the popup is open, so the ring stays drawn and a close lands on it.
type OutlineMorphRing = 'focus-visible' | 'focus-within'OutlineMorphTailProps
Props for OutlineMorphTail.
type OutlineMorphTailProps = {
/** `tailRef` from `useOutlineMorph`. */
ref: (element: HTMLElement | null) => void;
/** The adopter's class: the tail's size, and its rotation per `data-side` as the popup's own tail. */
className?: string;
/** The same drawing as the popup's tail (e.g. `OverlayTail`), its fill and stroke answering the cap. */
children?: React.ReactNode;
}UseOutlineMorphOptions
Options for useOutlineMorph.
type UseOutlineMorphOptions = {
/** The popup's open state, as its root has it after each commit. */
open: boolean;
/**
* Run the morph. Default `true`; `false` leaves the popup's own open and
* close, and a change of `open` committed with it false happens that way.
*/
enabled?: boolean;
/**
* How the trigger draws its focus ring. Default `focus-visible`: on the
* trigger while it matches `:focus-visible` (focus moves into the popup).
* `focus-within`: on a field's box whenever anything in it holds focus,
* pointer focus included (focus stays in its input).
*/
ring?: OutlineMorphRing;
/**
* Durations in ms, overriding the tokens. Default: the trigger's
* `--fgd-duration-expand` (333) and `--fgd-duration-collapse` (200), read
* at each open and close; 0 turns the morph off.
*/
duration?: OutlineMorphDuration;
/**
* A modal surface (a dialog, a sheet), whose frame sits in an
* `OutlineMorphLayer`: the durations default to the trigger's
* `--fgd-duration-expand-surface` (400) and
* `--fgd-duration-collapse-surface` (240). Default `false`.
*/
surface?: boolean;
}