Component specification: GhostPresence and overlay exit lifecycle
Important
Status: Design sign-off recorded for #412 (P1–P6 approved as proposed by Zac at 225f9fe09b1bbab8c03d88138c80ebdb171b6e01, recorded in PR #488 on 2026-11-28). Specification for 0.2.0 ("Motion and nested menus"), implemented for the first-release hosts by #417. Usage guide: GhostPresence.
Predecessors: ADR 0003: Public component API conventions, ADR 0004: Headless and styled layering, ADR 0011: Overlay primitives, ADR 0012: Modal overlays, Focus scope and roving focus, and Motion.
Purpose and user problems
Closing an overlay in @ghostvue/vue today (GhostDialogContent, GhostDialogOverlay, GhostPopoverContent, GhostDrawerContent, and peer surfaces) unmounts its DOM subtree synchronously via v-if="context.isOpen.value" (or v-if="visible"). As a result, @ghostvue/themes can animate overlay entry with @starting-style and CSS transitions, but every close snaps out of existence in a single frame.
Adding exit animations naively by delaying logical close or keeping modal/focus primitives alive until transitionend degrades keyboard and assistive-technology behavior:
- A keyboard user pressing
Escapeon a modalGhostDialogexpects focus to return to the trigger immediately so the very nextTaborEnteracts on the underlying page rather than being swallowed or yanked back 120–250ms later when a fade finishes. - Nested overlays (for example a
GhostPopoverinside aGhostDialog, or two stacked dialogs) need a second rapidEscapepress to dismiss the parent layer without hitting a lingering entry onlayerStack. - Page scrolling (
useScrollLock) and background sibling interactivity (useInertOthers) must unlock as soon as the final modal logically closes, and clicks through a fading scrim or popover must activate underlying controls rather than landing on a departing surface. - Headless consumers with zero CSS must still get immediate DOM removal without hanging on a
transitionendevent that never fires, and rapid close-then-reopen interactions must never let a stale animation completion unmount newly reopened content.
GhostPresence and useGhostPresence decouple logical open state (isOpen) from physical DOM presence (isPresent): accessibility, dismissal, focus restoration, focus trapping, background inert, and scroll lock follow logical close immediately, while DOM removal waits only when active CSS transitions or animations run on the exiting surface.
Vue <Transition> versus GhostPresence and useGhostPresence
| Dimension | Vue <Transition> | GhostPresence / useGhostPresence |
|---|---|---|
| Styling contract | Injects transient framework classes (v-enter-from, v-leave-active, v-leave-to) or requires imperative JS @leave(el, done) hooks. | Uses GhostVue's canonical data-state="open" | "closed" hook (public-api.md, motion.md) alongside @starting-style for entry. |
| Headless default (absent CSS motion) | JS @leave hooks hang unless manually probing computed styles; class-based leave requires consumer/theme transition classes. | Inspects animations/transitions targeting the surface element after data-state="closed" flushes; when effective duration is 0ms, unmounts in the same post-flush tick with zero timer delay. |
GhostPortal (<Teleport>) | Cannot wrap <GhostPortal> directly (<Teleport> has no single element root); wrapping inside each part still ties component unmount lifecycle to physical leave completion. | Composes inside <GhostPortal> without moving nodes back inline during exit; useGhostPresence runs directly inside overlay content/overlay parts with zero extra wrapper components. |
| Focus, trap, layer, and scroll timing | Keeping a dialog component mounted during <Transition> leave keeps onMounted/onUnmounted-scoped traps, layerStack, inert, and scroll lock active unless split manually. | Logical isOpen drives useFocusScope, useDismissableLayer, useScrollLock, and useInertOthers (immediate release on close); isPresent drives only v-if DOM retention and useFloating. |
| Interrupted exit / rapid reopen | v-if false-then-true either instantiates a new component subtree or requires leave cancellation coordination across VNode clones. | Keeps the same mounted DOM element and component instance alive while exiting, increments a generation counter on reopen, flips data-state back to "open", and interpolates smoothly from mid-exit. |
| Descendant transition isolation | Bubbled transitionend / animationend from child controls (for example button hover or an infinite GhostSpinner) can prematurely end or indefinitely block poorly scoped hooks. | Tracks only animations/transitions whose target is the registered surface element itself (element.getAnimations() without subtree: true, and event.target === element fallback). |
Consumers who animate arbitrary non-GhostVue elements inside an overlay's default slot may still use Vue <Transition> normally; GhostPresence owns the overlay surface and backdrop lifecycle.
Non-goals
- JavaScript physics, spring solvers, or Web Animations orchestration in
@ghostvue/vue. Headless code never computes keyframes, durations, or curves; all visual motion lives in@ghostvue/themesor consumer CSS. - View Transitions API orchestration for overlays.
startThemeTransitionin@ghostvue/themesremains scoped to theme mode crossfades. - Drag-to-dismiss or swipe-velocity gestures on
GhostDrawerorGhostDialog. - Multi-item list exit choreography (
<TransitionGroup>). Keyed toast stack exits (GhostToastViewport/GhostToast) require list reflow coordination and remain outside this single-surface presence contract. - Nested menu (
GhostDropdownMenu,GhostContextMenu,GhostMenubar) and persistent-DOM listbox (GhostSelect,GhostCombobox) exit wiring in the first slice (#417). See First-release overlay hosts for exact boundaries and follow-up sequencing. - Waiting on persistent infinite animations. Unbounded animations applied to the registered surface itself (
animation-iteration-count: infinite, or any animation with a non-finite end time orplaybackRate === 0) are explicitly excluded from exit completion waiting so closed overlays and floatingautoUpdatehosts never hang indefinitely. - New runtime dependencies. Implemented entirely in
@ghostvue/vueusing standard DOM/Web Animations APIs (getAnimations,getComputedStyle,transitionend/animationend).
Public API
All runtime exports live in @ghostvue/vue. @ghostvue/themes exports no new JavaScript symbols; its contribution is CSS exit rules in existing component stylesheets (see Rendering and customization).
Exports from @ghostvue/vue
GhostPresence— renderless presence component for custom consumer overlays and conditional subtrees.useGhostPresence— headless composable used by GhostVue overlay parts and advanced standalone compositions.- Types:
GhostPresencePhase,GhostPresenceDataState,GhostPresenceProps,GhostPresenceSlotProps,UseGhostPresenceOptions,UseGhostPresenceReturn.
useGhostPresence composable
export type GhostPresencePhase = 'closed' | 'open' | 'exiting'
export type GhostPresenceDataState = 'open' | 'closed'
export interface UseGhostPresenceOptions {
/** Logical open state (`true` while open, `false` when logically closed). */
present: MaybeRefOrGetter<boolean>
/**
* Host element (HTML or SVG) whose own CSS transitions/animations gate DOM
* removal during the `exiting` phase. Optional when binding `setElement` as a
* template ref.
*/
element?: MaybeRefOrGetter<Element | null | undefined>
/**
* Skips exit retention when `true` (for example `disableAnimation` or an
* anchored overlay closed before initial positioning completed).
* @default false
*/
disabled?: MaybeRefOrGetter<boolean | undefined>
/**
* Invoked once after an `exiting` surface finishes its exit motion and flips
* `isPresent` to `false`. Never called when an exit is interrupted by reopen
* or aborted by owner component unmount.
*/
onExitComplete?: () => void
}
export interface UseGhostPresenceReturn {
/** `true` while `present` is `true` or while `phase` is `'exiting'`. */
isPresent: ComputedRef<boolean>
/** Current lifecycle phase: `'closed'`, `'open'`, or `'exiting'`. */
phase: Readonly<Ref<GhostPresencePhase>>
/** `'open'` when logically open; `'closed'` during `'exiting'` and `'closed'`. */
dataState: ComputedRef<GhostPresenceDataState>
/** `true` only while `phase` is `'exiting'`. */
isExiting: ComputedRef<boolean>
/**
* Template-ref setter accepting a raw `Element`, a component instance exposing
* `{ element: Element | null }` or an `Element` `$el`, or `null`. Used when `options.element`
* is not passed directly.
*/
setElement: (target: unknown) => void
}GhostPresence component
Props and configuration
| Prop | Type | Default | Contract |
|---|---|---|---|
present | boolean | required | Logical open/mounted state. When true, mounts the default slot; when false, transitions through exiting before unmount. |
disabled | boolean | false | When true, bypasses exit waiting and unmounts immediately when present turns false. |
v-model contracts
GhostPresence does not own open state and defines no v-model. present is a one-way boolean input driven by the parent or an enclosing overlay's open state. Built-in overlay roots (GhostDialog, GhostPopover, GhostDrawer, GhostCommandPalette, GhostDatePicker, GhostHoverCard) keep their existing v-model:open (open + update:open) contracts unchanged: update:open(false) emits synchronously at logical close, never delayed until exit completion.
Events, callbacks, slots, and exposed methods
- Emits:
exitComplete: []— emitted when an exit finishes and the slot unmounts (onExitCompleteequivalent). Not emitted on reopen interruption or parent unmount. The component emits it after the DOM update that removes the slot, so a synchronous listener already sees the departing node disconnected. The composable'sonExitCompletecallback keeps its timing: it runs whenphasebecomes'closed', before that render. - Default slot (
GhostPresenceSlotProps):{ present: boolean, phase: GhostPresencePhase, state: GhostPresenceDataState, exiting: boolean, setElement: (target: unknown) => void }.- When
!isPresent,GhostPresencereturnsnullwithout invoking the default slot (matchingv-if="false"). - When
isPresentistrueand the default slot renders a single element or component VNode without manually callingsetElement,GhostPresenceclones the VNode (cloneVNode(..., /* mergeRef */ true)) to compose its element ref without clobbering any consumerref, injectsdata-state="open" | "closed"when the child omitsdata-state, and appliesinertpluspointer-events: nonewhileexiting(preserving any consumer-suppliedinertor inlinepointer-eventsonce reopened). A component root that does not forward those attributes (inheritAttrs: false, or one that declares them as props) has the missing ones applied directly to its resolved DOM root after each patch; on reopen only the attributesGhostPresenceadded are removed. From exit start to exit end,GhostPresenceownspointer-events,inertand thedata-stateit injects on such a root. The guard holds even if the component re-renders its root:pointer-events: noneis enforced again, a removedinertis put back, anddata-state="closed"is restored if the component overwrites it. On reopen, an injecteddata-statereturns toopen, andGhostPresencerestores the inlinepointer-eventscaptured at exit start, unless the reopen render wrote a value other thannone. Aninertthe component set itself during the exit stays. A component that changedpointer-eventsduring the exit re-applies its own value afterwards;GhostPresencedoes not replay it (see Post-approval amendments). - The surface is any DOM
Element, so a direct<svg>root (anSVGElement) and a component whose single root is an<svg>(resolved through its$el) keep their exit motion exactly like an HTML root. A component exposingelementis resolved through that first.inertis an HTML attribute and does not make SVG content inert, so on an SVG root onlypointer-events: noneapplies while exiting; wrap an SVG that contains focusable content in an HTML element and animate that instead. - When the default slot renders a fragment, multiple root nodes, or a
<Teleport>/GhostPortalwrapper, the consumer binds:ref="setElement"(anddata-state/:inert="exiting || undefined") on the animated surface element. In development builds (process.env.NODE_ENV !== 'production'), ifpresentflipstrue -> falsewith no resolvedElementbecause a non-element root did not bindsetElement,GhostPresencelogs the next unassignedGHOST0xxwarning inpackages/vue/src/dev-codes.tsonce and unmounts immediately rather than hanging.
- When
- Exposed: none (
GhostPresenceis renderless; consumers keep their own template ref on the child element, preserved bymergeRef).
Minimal consumer examples
1. Built-in overlay host (zero extra markup)
Built-in hosts wire useGhostPresence internally. Consumers using @ghostvue/themes get themed exit motion automatically; headless consumers write plain CSS against [data-state='open'] and [data-state='closed']:
<script setup lang="ts">
import { ref } from 'vue'
import {
GhostDialog,
GhostDialogClose,
GhostDialogContent,
GhostDialogDescription,
GhostDialogOverlay,
GhostDialogTitle,
GhostDialogTrigger,
} from '@ghostvue/vue'
const open = ref(false)
</script>
<template>
<GhostDialog v-model:open="open">
<GhostDialogTrigger>Delete project</GhostDialogTrigger>
<GhostDialogOverlay class="dialog-scrim" />
<GhostDialogContent class="dialog-panel">
<GhostDialogTitle>Delete project?</GhostDialogTitle>
<GhostDialogDescription>
This action permanently removes all snapshots.
</GhostDialogDescription>
<GhostDialogClose>Cancel</GhostDialogClose>
</GhostDialogContent>
</GhostDialog>
</template>
<style scoped>
.dialog-scrim,
.dialog-panel {
transition: opacity 120ms cubic-bezier(0.3, 0, 1, 1);
@starting-style {
opacity: 0;
}
}
.dialog-scrim[data-state='closed'],
.dialog-panel[data-state='closed'] {
opacity: 0;
}
</style>2. Standalone GhostPresence with GhostPortal
<script setup lang="ts">
import { ref } from 'vue'
import { GhostPortal, GhostPresence } from '@ghostvue/vue'
const open = ref(false)
</script>
<template>
<button type="button" :aria-expanded="open" @click="open = !open">
Toggle inspector
</button>
<GhostPortal>
<GhostPresence :present="open">
<aside class="inspector-panel" aria-label="Inspector">
<p>Panel details</p>
</aside>
</GhostPresence>
</GhostPortal>
</template>
<style scoped>
.inspector-panel {
transition:
opacity 120ms ease,
translate 120ms ease;
@starting-style {
opacity: 0;
translate: 0 0.5rem;
}
}
.inspector-panel[data-state='closed'] {
opacity: 0;
translate: 0 0.5rem;
}
</style>First-release overlay hosts
The first implementation release (0.2.0, tracked by #417) adopts useGhostPresence and @ghostvue/themes exit recipes in the following hosts (approved per P2):
| Host family | Headless parts adopting useGhostPresence | Why in (or out of) the first 0.2.0 release (#417) |
|---|---|---|
| Standalone primitive | GhostPresence, useGhostPresence | Public building block for custom overlays and internal host parts. |
Dialog (GhostDialog) | GhostDialogContent, GhostDialogOverlay | Primary modal and modal=false regression fixture required by #412 and #417. |
Popover (GhostPopover) | GhostPopoverContent | Primary anchored non-modal regression fixture required by #412 and #417. |
Drawer (GhostDrawer) | GhostDrawerContent, GhostDrawerOverlay | Shares useDialogContentPart / useDialogOverlayPart in dialog-shared.ts with GhostDialog; already has @starting-style edge slides in ghost-drawer.css. |
| CommandPalette | GhostCommandPaletteContent, GhostCommandPaletteOverlay | Shares useDialogContentPart / useDialogOverlayPart in dialog-shared.ts and entry scale/fade in ghost-command-palette.css. |
DatePicker (GhostDatePicker) | GhostDatePickerContent (via inner GhostDialogContent) | Wraps GhostDialogContent; included so useFloating retains anchor coordinates while the inner GhostDialogContent exits. |
HoverCard (GhostHoverCard) | GhostHoverCardContent | Non-modal v-if floating dialog surface with an existing entry recipe in ghost-hover-card.css. |
Menus (deferred past #417) | GhostDropdownMenuContent, GhostContextMenuContent, Menubar | Deferred until nested submenus (#413, #418, #419) land so #417 avoids file conflicts and Menubar horizontal menu-switch handoff is designed against settled submenu semantics. |
Listboxes (deferred past #417) | GhostSelectContent, GhostComboboxContent | Deferred: both keep DOM mounted with hidden while closed so options stay registered, and GhostSelect has parallel 0.2.0 work (#415 / #421). |
Tooltip (deferred past #417) | GhostTooltipContent | Deferred: ghost-tooltip.css currently defines no entry transition; tooltip fade policy can opt in later without blocking modal/dialog overlays. |
| Toast (out of scope) | GhostToastViewport / GhostToast | Out of scope: keyed v-for stack requires list-item exit and layout reflow choreography rather than single-surface presence. |
Overlay host parts add no required props in #417 (zero breaking or ceremonial changes to consumer templates; see P3 regarding omitted forceMount).
State model
Lifecycle stages and timing guarantees
useGhostPresence models three deterministic phases: 'closed', 'open', and 'exiting'. Every overlay subsystem binds strictly to either logical open (isOpen) or physical presence (isPresent):
| Stage | isOpen | phase | isPresent | Trigger aria-expanded / data-state | Surface data-state | Focus & useFocusScope (trappedStack) | useDismissableLayer (layerStack) | useScrollLock & useInertOthers (modal) | Surface interactivity & AT exposure | useFloating (x, y, data-placement) |
|---|---|---|---|---|---|---|---|---|---|---|
| 1. Closed | false | 'closed' | false | "false" / "closed" | unmounted | Inactive (0 listeners) | Inactive (0 listeners) | Inactive (lockCount = 0, no inert) | Unmounted (not in DOM or portal) | Inactive |
| 2. Opening (pre-positioned) | true | 'open' | true | "true" / "open" | "open" | Waiting for portal tick / isPositioned / focusReady | Active on layerStack | Active immediately on modal open | Mounted; floating hosts keep visibility: hidden | Computing initial coordinates |
| 3. Open (active) | true | 'open' | true | "true" / "open" | "open" | Active; autofocused; trapped if modal=true | Active on layerStack | Active (overflow: hidden, sibling inert) | Interactive; exposed in accessibility tree (role="dialog") | Active (autoUpdate running; visibility: hidden removed) |
4. Logical close (exiting) | false | 'exiting' | true | "false" / "closed" immediately | "closed" | Deactivated immediately; trap released; focus restored | Removed immediately | Released immediately | Non-interactive & hidden from AT (inert + pointer-events: none) | Retained until unmount so surface never jumps to (0,0) |
| 5. DOM removal (exit settled) | false | 'closed' | false | "false" / "closed" | unmounted | Inactive (focus untouched — never re-restored on DOM removal) | Inactive | Inactive | Unmounted from DOM and GhostPortal | Cleaned up (stopAutoUpdate) |
Key invariants of Stage 4 (Logical close):
- Controlled state gate: When
openis controlled and the parent ignoresupdate:open(false),context.isOpen.valuestaystrue. Logical close does not occur,phaseremains'open',data-statestays'open', focus does not restore, and modal locks stay active. - Synchronous phase transition before unmount: On a mounted client, when
presenttransitionstrue -> false(anddisabledisfalse), aflush: 'sync'watcher flipsphasefrom'open'to'exiting'before Vue re-evaluates the component render effect, keepingisPresent.value === trueacross the close render so the DOM node is retained without unmounting and remounting. - Ordering of sibling
inertrelease, focus restoration, and surfaceinert:- First,
useInertOthersclearsinertfrom background siblings (including the trigger) anduseScrollLockdecrementslockCount. - Second,
useFocusScoperemoves any modal entry fromtrappedStackand restores focus synchronously (toreturnFocus?.()or the saved opener, unless suppressed by a non-modal outside click on a focusable control orTabdeparture). Modal outside-pointer dismissal preserves the existing ChromiummousedownpreventDefault()guard and WebKit next-task<body>focus reapply (dialog-shared.ts). - Third, the exiting surface (and any modal backdrop) receives
inertandpointer-events: none. Because focus has already moved out of the overlay whenrestoreFocusapplies (and blurs cleanly ifrestoreFocuswas intentionally suppressed while focus sat inside), focus never remains trapped inside an exiting subtree, and a user who pressesTabmid-exit never has focus yanked back when Stage 5 removes the DOM node.
- First,
Exit completion detection
After Vue flushes the close render (data-state="closed", flush: 'post'):
- Immediate bailouts: If
disabledistrue, noElementis resolved,!element.isConnected, or (for anchored floating hosts) the overlay closed beforeisPositionedever resolved totrueduring that opening (meaning the surface was stillvisibility: hidden),useGhostPresencesetsphase = 'closed'immediately in that post-flush callback. - Web Animations inspection (primary browser path): When
typeof element.getAnimations === 'function'(Chromium, Firefox, WebKit):- Call
element.getAnimations()without{ subtree: true }, collecting only animations and CSS transitions whoseeffect.targetiselementitself (descendant transitions such as button hovers or infiniteGhostSpinneranimations inside the slot are ignored). - Inspect
effect.getComputedTiming()(falling back toeffect.getTiming()in minimal synthetic mocks) and filter to animations that satisfy all of:playStateis'pending'or'running';playbackRate !== 0(paused or zero-rate animations cannot advance to a settled end state);- finite end time:
Number.isFinite(endTime)anditerations !== Infinity(with finitedurationwhen falling back togetTiming()). Persistent infinite animations on the registered surface itself (for exampleanimation: pulse 1s infinite, whereiterations === InfinityandendTime === Infinity) are explicitly excluded and never gate DOM removal; - positive remaining time:
remainingMs > 0(and finite), whereremainingMs = endTime - (localTime ?? 0)forplaybackRate > 0,remainingMs = localTime ?? 0forplaybackRate < 0, ordelay + duration * iterations > 0when onlygetTiming()is exposed.
- If the filtered list is empty (including when only an infinite animation is running on the surface), transition
phase = 'closed'synchronously in the same post-flush callback (zerorequestAnimationFrameor timer lag). - Otherwise,
await Promise.allSettled(animations.map((anim) => anim.finished))so both normal finite completion (including finite multi-iteration animations such asanimation-iteration-count: 3) and browser animation cancellation (AbortError, for exampledisplay: noneon an ancestor or DevTools disabling animations) settle without stranding the node or floatingautoUpdateresources. If an excluded infinite animation runs alongside a finite exit transition on the same element, only the finite transition entersPromise.allSettled. When all awaited animations settle, if the exit attempt ID is still current, setphase = 'closed'and invokeonExitComplete?.(). - Bound that wait with a safety timer of
Math.ceil(maxRemainingMs) + 34ms, wheremaxRemainingMsis the longestremainingMs / |playbackRate|(wall-clock time) among the awaited animations, the same margin as the fallback below. An animation paused after this inspection (pause()or a change toanimation-play-state) never settlesfinished, and without the timer it would hold the hidden surface and itsautoUpdateresources indefinitely. When the timer fires, re-run the same filter on the awaited animations. If any is still advancing (for example itsplaybackRatewas lowered), re-arm the timer for its new wall-clock remaining time plus34ms. Only when none can advance (paused, idle, finished or zero-rate) does the timer complete the exit. Whichever comes first, the settled promises or that completion, ends the exit once; the other is cancelled.
- Call
- Computed-style + event fallback (environments without
getAnimations, such as jsdom):- Read
getComputedStyle(element)fortransitionProperty,transitionDuration,transitionDelay,animationName,animationDuration,animationDelay,animationIterationCount, andanimationPlayState. - Parse comma-separated CSS time lists (
msands) and cycle shorter lists modulo their length per CSS Transitions and CSS Animations list-matching rules:- Transitions: Skip entries whose matched
transitionPropertyis'none'. Each remaining entry contributesMath.max(0, delayMs + durationMs), including entries with zero duration. Fortransition: opacity 0ms 100ms, the opacity change occurs after the delay, so keep the exiting surface mounted through that delay. - Animations: Skip entries whose matched
animationNameis'none'or''. Apply an explicit exclusion policy for infinite counts: any animation whose matchedanimationIterationCountis'infinite'(case-insensitive) is excluded from exit completion waiting (0mscontribution, consistent with the primary Web Animations path). Entries whose matchedanimationPlayStateis'paused'(case-insensitive) are excluded the same way: a paused animation never dispatchesanimationend, so it must not hold the surface until the safety timer. For finite numeric iteration counts (Number.isFinite(count) && count > 0) anddurationMs > 0, compute the active duration asdurationMs * countand total completion time asMath.max(0, delayMs + durationMs * count)(for exampleanimation-duration: 100mswithanimation-iteration-count: 3contributes300ms). Non-positive or invalid iteration counts anddurationMs <= 0contribute0ms. - Let
maxTotalMsbe the maximum across all included transitions and finite animations.
- Transitions: Skip entries whose matched
- If
maxTotalMs <= 0(including when only aninfiniteanimation is present), setphase = 'closed'immediately. - Otherwise, listen for
transitionend,transitioncancel,animationend, andanimationcancelfiltered strictly toevent.target === element(ignoringanimationend/animationcancelwhoseevent.animationNamematches only an excludedinfiniteanimation). Each included transition property and finite animation entry is outstanding until its own end or cancel event (matched byevent.propertyName/event.animationName; atransition-property: allentry is settled by an event for any undeclared property), and the exit completes only when none remain, sotransition: opacity 100ms, transform 300msstays mounted through the transform. Add a safety timer ofMath.ceil(maxTotalMs) + 34ms (for example334msfor a100ms×3exit animation) so synthetic DOM hosts that do not dispatch events automatically still converge without cutting off finite multi-iteration animations or leaking nodes.
- Read
Reduced and absent motion
- Absent motion (headless
@ghostvue/vue, unstyled CSS,transition: none, or--ghost-motion-intensity: 0): Computed transition and animation durations resolve to0s(calc(<ms> * 0)=0ms). With no positive transition delay, bothgetAnimations()and thegetComputedStylefallback observe zero active motion and setphase = 'closed'in the post-flush tick, unmounting the DOM node immediately. - Reduced motion (
@media (prefers-reduced-motion: reduce)): Per Motion,@ghostvue/themescollapses spatial travel (translate: none/0px,scale: 1) and runs a short opacity-only fade overvar(--ghost-motion-fade-duration)(80msat default intensity) withvar(--ghost-motion-easing-standard)so the dismissal remains visually perceivable without vestibular motion.useGhostPresencedoes not hardcode amatchMedia('(prefers-reduced-motion: reduce)')bypass in JS: it follows the active CSS duration, so@ghostvue/themes's80msopacity fade runs to completion while a consumer stylesheet that setstransition: noneunderprefers-reduced-motion: reduceunmounts in0ms.
Interrupted exits, rapid reopen, and stale completion events
useGhostPresence maintains a monotonically increasing integer attemptId:
- Reopen during
'exiting'(present: false -> true):attemptIdincrements immediately, invalidating any in-flightPromisecontinuation, event listener, or fallback timer from the interrupted exit.- Registered exit event listeners and fallback timers for the prior attempt are detached/cleared synchronously.
phaseflips immediately from'exiting'to'open'on the same mounted DOM element (isPresentstaystruethroughout — no DOM unmount/remount).data-statereturns to'open', library-appliedinertandpointer-events: noneare removed immediately, and browser CSS transitions smoothly reverse from the current mid-exit interpolated style back to the open resting values.- Host composables (
useFocusScope,useDismissableLayer,useScrollLock,useInertOthers) seeisOpenflipfalse -> trueand re-activate cleanly for the new opening (capturing the current active element asopenerAtOpen, re-locking scroll and backgroundinertfor modals, and focusing inside the reopened overlay).
- Stale completion events: Any late
transitionend,animationend,transitioncancel,animationcancel, fallback timer callback, or microtask resolution from an olderattemptIdchecksattemptId === activeAttemptId && phase.value === 'exiting'before mutating state. When stale, it is a no-op: it never setsphase = 'closed', never unmounts the reopened (or newly re-exiting) element, and never firesonExitComplete.
Loading, empty, disabled, read-only, and error states
GhostPresence supports disabled (UseGhostPresenceOptions.disabled), which forces immediate unmount on close without entering 'exiting'. Trigger and close button disabled states on overlay hosts remain owned by each host component.
Async behavior
Exit waiting is asynchronous on the client when CSS motion has positive duration. All async continuations (Promise.allSettled on Animation.finished, DOM event listeners, and fallback timers) are guarded by attemptId and an isUnmounted flag so out-of-order completions, rapid open -> close -> open -> close cycles, and component teardown cannot corrupt state or touch disposed Vue scopes.
Component and ancestor unmount
When the owning component (GhostDialogContent, GhostPopoverContent, or GhostPresence) unmounts while 'open' or 'exiting' (for example because an ancestor v-if or route view unmounted):
onUnmountedincrementsattemptId, setsisUnmounted = true, removes any pending transition/animation listeners, and clears any fallback timer.onExitComplete/exitCompleteis not called on owner unmount.<GhostPortal>(<Teleport>) removes the portaled DOM subtree immediately as part of Vue's normal unmount pass.useScrollLock,useInertOthers,useDismissableLayer,useFocusScope, anduseFloatingclean up via their existingonUnmountedhooks, leaving zero orphan DOM nodes, scroll locks,inertattributes, ordocumentlisteners.
Consumer data
GhostPresence and useGhostPresence accept no domain collections, item arrays, or value models, and never mutate consumer data objects. On the managed host Element, DOM attribute writes during 'exiting' are strictly scoped: if the element already carried a consumer-authored inert attribute while 'open', that attribute is preserved across reopen rather than stripped (matching the ownership rule in useInertOthers). Consumer class and style bindings merge cleanly and are never overwritten.
Accessibility contract
Semantics and relationships
GhostPresencerenders no wrapper element and adds no ARIA roles of its own.- Overlay triggers (
GhostDialogTrigger,GhostPopoverTrigger,GhostDrawerTrigger,GhostHoverCardTrigger) bindaria-expandedanddata-stateto logicalisOpen, soaria-expandedswitches to"false"the instant dismissal occurs rather than lagging behind a visual fade. - Overlay content parts keep their semantic
id,role,aria-labelledby, andaria-describedbyattributes while mounted, but remove the exiting surface from the accessibility tree immediately at logical close via native HTMLinert(below). Because reopening during'exiting'reuses the same mounted element, no duplicateidattributes ever coexist in the document. - Development diagnostics (
GHOST002missing accessible name,GHOST003missing alertdialog description) run only while logicallyopen, never re-firing during'exiting'.
Keyboard interaction
GhostPresence registers no keyboard handlers. In overlay hosts:
| Key | Stage | Behavior |
|---|---|---|
Escape | 'open' | Dismisses the topmost open layer on layerStack, starts 'exiting', and restores focus immediately. |
Escape | 'exiting' | Closing layer is already off layerStack; Escape immediately reaches the next open parent overlay beneath (or passes through to the page). |
Tab / Shift+Tab | 'open' (modal) | Trapped within the modal surface by useFocusScope. |
Tab / Shift+Tab | 'exiting' (modal) | Trap is already released; Tab moves naturally from the restored trigger through normal page tab order without entering the exiting surface. |
Enter / Space | Restored trigger | Immediately reopens the overlay ('exiting' -> 'open') if pressed while the previous exit animation is still running. |
Focus behavior
- Immediate focus restoration on logical close:
useFocusScopedeactivates whenisOpenturnsfalse(not whenisPresentturnsfalse). Focus returns synchronously toreturnFocus?.()or the saved opener/trigger before the exit animation plays. - No double restoration at physical unmount: When the exit animation later finishes and
isPresentturnsfalse,useFocusScopeis already inactive, so removing the DOM node never movesdocument.activeElementa second time (even if the user has already tabbed or clicked elsewhere during the exit). - Non-modal outside focusable click: Clicking an outside button or input while a
GhostPopoveror non-modalGhostDialogis open suppressesrestoreFocusas today, keeps focus on the clicked control, and animates the popover closed without stealing focus. - Programmatic close with suppressed restoration: If focus was inside an overlay when it closed programmatically with restoration suppressed, applying
inertto the exiting surface blurs focus cleanly rather than leavingactiveElementinside a disappearing subtree.
Exiting interactivity and assistive-technology exposure
| Stage | Pointer / touch hit-testing | Keyboard / .focus() reachability | Assistive-technology tree exposure |
|---|---|---|---|
'open' | Interactive (pointer-events normal / auto) | Focusable and tabbable per role | Exposed (role="dialog" | "alertdialog", aria-modal="true" when modal) |
'exiting' (content) | Non-interactive (inert + pointer-events: none) | Unfocusable (inert) | Pruned from accessibility tree (inert; passes axe aria-hidden-focus) |
'exiting' (modal backdrop) | Pass-through (pointer-events: none) | Unfocusable (aria-hidden="true") | Hidden (aria-hidden="true", unchanged from 'open') |
'closed' | Unmounted | Unmounted | Unmounted |
Why HTML inert + pointer-events: none instead of aria-hidden="true" alone: placing aria-hidden="true" on an exiting dialog that still contains enabled <button> or <input> descendants violates WCAG / axe-core's aria-hidden-focus rule because descendants remain programmatically/sequentially focusable unless disabled or inert. Native inert simultaneously removes the subtree from the accessibility tree, prevents all focus entry (also honored by getTabbableElements in packages/vue/src/get-tabbable-elements.ts), and blocks hit-testing, while explicit pointer-events: none guarantees clicks pass through even when a component stylesheet sets pointer-events: auto (such as GhostHoverCardContent) or in synthetic test environments.
Rendering and customization
Headless versus theme motion boundary
@ghostvue/vue(headless):- Renders
data-state="open"while logically open anddata-state="closed"while'exiting'. - Applies
inertand inlinepointer-events: nonewhile'exiting'so departing overlays never block pointer clicks on uncovered controls. - Retains floating inline styles (
position,left,top) anddata-placementon anchored surfaces (GhostPopoverContent,GhostHoverCardContent,GhostDatePickerContent) throughout'exiting'. - Ships no CSS transitions, keyframes, durations, or
@ghostvue/themesimports.
- Renders
@ghostvue/themes(optional styled layer):- Owns all visual enter and exit transitions under
@layer ghostvue-theme, parameterized exclusively by semantic--ghost-motion-*tokens frompackages/themes/tokens/semantic.json(respecting--ghost-motion-intensityanddata-ghost-mode). - Base geometry selector rule: Surface and backdrop layout, positioning, elevation, and
@media (forced-colors: active)rules inghost-dialog.cssandghost-drawer.cssmust match.ghost-dialog-content,.ghost-dialog-overlay,.ghost-drawer-content, and.ghost-drawer-overlaywithout requiring[data-state='open'](matchingghost-popover.cssandghost-command-palette.css), so flipping to[data-state='closed']never dropsposition: fixed, centeringtransform, edge offsets, or system-color paint mid-exit.
- Owns all visual enter and exit transitions under
@ghostvue/themes exit recipes
Under @media (prefers-reduced-motion: no-preference), exits run faster than or equal to enters using --ghost-motion-exit-duration (120ms scaled by --ghost-motion-intensity) and --ghost-motion-exit-easing (cubic-bezier(0.3, 0, 1, 1)):
| Surface / part | Entry ([data-state='open'] + @starting-style) | Exit ([data-state='closed'], no-preference) | Reduced motion (prefers-reduced-motion: reduce, [data-state='closed']) |
|---|---|---|---|
GhostDialogOverlay, GhostDrawerOverlay, GhostCommandPaletteOverlay | opacity: 0 -> 1 (--ghost-motion-duration-fast / --ghost-motion-enter-duration) | opacity: 0 over var(--ghost-motion-exit-duration) var(--ghost-motion-exit-easing) | opacity: 0 over var(--ghost-motion-fade-duration) var(--ghost-motion-easing-standard) |
GhostDialogContent (and GhostDatePickerContent via GhostDialogContent) | opacity: 0 -> 1, translate: 0 calc(var(--ghost-motion-translate) / 2) -> 0 (full-size) | opacity: 0; translate: 0 calc(var(--ghost-motion-translate) / 2) over --ghost-motion-exit-duration + exit easing | opacity: 0; translate: none over --ghost-motion-fade-duration + --ghost-motion-easing-standard |
GhostDrawerContent (start, end, top, bottom × ltr / rtl) | opacity: 0 -> 1, edge translate (±100% 0 or 0 ±100%) over --ghost-motion-enter-* | opacity: 0 + matching physical edge translate (±100% 0 or 0 ±100%) over --ghost-motion-exit-* (see P6) | opacity: 0; translate: none over --ghost-motion-fade-duration + --ghost-motion-easing-standard |
GhostPopoverContent, GhostHoverCardContent, GhostCommandPaletteContent | opacity: 0 -> 1, scale: 0.98 -> 1 over --ghost-motion-duration-fast + enter easing | opacity: 0; scale: 0.98 over var(--ghost-motion-exit-duration) var(--ghost-motion-exit-easing) | opacity: 0; scale: 1 over --ghost-motion-fade-duration + --ghost-motion-easing-standard |
All recipes keep zero hardcoded color, pixel, rem, or millisecond/second literals so tests/integration/ghost-*-theme-css.test.ts token checks continue to pass.
Environment behavior
Portals
- Overlay parts keep
<GhostPortal :to="portalTo" :disabled="!portal">unchanged across'open'and'exiting';v-if="presence.isPresent.value"sits on the inner surface element. - Exiting content therefore stays inside
portalTo(document.bodyby default) untilisPresentturnsfalse. It never teleports back inline on logical close, which would clip fixed/floating geometry insideoverflowancestors and cancel active CSS transitions due to DOM reparenting. - If
portalorportalTois dynamically changed by the consumer during'exiting', DOM reparenting cancels running CSS transitions (transitioncancel/ rejectedAnimation.finished), whichuseGhostPresencetreats as settled and unmounts cleanly.
SSR and hydration
useGhostPresencetouches zero browser globals (window,document,HTMLElement,getComputedStyle) duringsetup.- Closed overlays (
defaultOpen: false) haveisPresent.value === falseon the server and first client render, emitting the exact trigger-only SSR HTML tested inpackages/vue/src/overlay-ssr.test.ts. - Initially open overlays (
defaultOpen: true) haveisPresent.value === true,data-state="open", and noinerton both server and initial client hydration pass (rendered inline untilGhostPortal'sonMountedmoves them toportalTo), producing zero hydration mismatches (expectSsrHydration). - Any
present: true -> falsemutation beforeonMountedtransitions directly to'closed'without entering'exiting'.
Mobile and touch
- Outside
pointerdowndismissal on touch/pen releases the modal scrim's pointer interception (pointer-events: none) synchronously on logical close, so touch scrolling (useScrollLockunlocked) and follow-up taps on underlying controls work immediately without waiting for the scrim fade. - Dynamic viewport units (
dvh/dvw) onGhostDialogContentandGhostDrawerContentremain intact during'exiting'.
Performance
- Closed cost is zero: When
phase === 'closed', overlays remain unmounted viav-ifwith zero DOM nodes, zeroResizeObserver/autoUpdateinstances, and zerodocumentlisteners. - Constant-time state machine: One
shallowRefphase, one integer generation counter, and zeroMutationObserverorrequestAnimationFramepolling loops. - Subtree-isolated animation lookup:
element.getAnimations()without{ subtree: true }inspects only the single overlay surface element (O(animations on surface), typically 1–2 properties), avoiding O(subtree) walks over large dialog forms or tables. - Bundle budget:
useGhostPresence+GhostPresenceis ~1–1.5 kB minified (~0.6 kB gzip) with zero external dependencies; checked bypnpm size.
Composition
useGhostPresence/GhostPresence: New low-level presence primitive in@ghostvue/vue.dialog-shared.ts(useDialogContentPartanduseDialogOverlayPart): IntegratesuseGhostPresenceonce forGhostDialog,GhostDrawer, andGhostCommandPalette(andGhostDatePickerContentviaGhostDialogContent). SeparatespresentElement(live whileisPresentistrue, used for DOM ref resolution) from active open gating (context.isOpen.value, used byuseScrollLock,useInertOthers,useDismissableLayer,useFocusScope, andGHOST002/GHOST003diagnostics).- Floating hosts (
GhostPopoverContent,GhostHoverCardContent,GhostDatePickerContent): PasspresentElementtouseFloatingso resolved coordinates anddata-placementpersist throughout'exiting', while passing the open-gated element (isOpen ? presentElement : null) touseDismissableLayeranduseFocusScope. Skip exit retention (disabled: () => !wasPositioned) if closed before initialisPositionedresolved. - No duplicate focus-trap, layer-stack, scroll-lock, or portal code is introduced.
Test plan
Browser test matrix (modal GhostDialog and non-modal GhostPopover)
Playwright specs (tests/e2e/presence.spec.ts, plus updates to tests/e2e/dialog.spec.ts and tests/e2e/popover.spec.ts) use real keyboard/pointer events, toBeFocused(), computed style / getAnimations() checks, and explicit controllable CSS transition durations (for example 250ms in deterministic race fixtures alongside real @ghostvue/themes recipes):
| # | Scenario | Modal host (GhostDialog, modal=true) observable assertions | Non-modal host (GhostPopover) observable assertions | Engine coverage |
|---|---|---|---|---|
| 1 | Logical close via Escape (mid-exit) | Within 1 frame of Escape: trigger aria-expanded="false", content & overlay still in DOM inside body with data-state="closed", content has inert, trigger toBeFocused(), body scroll unlocked, page siblings not inert. | Within 1 frame of Escape: trigger aria-expanded="false", content still in body with data-state="closed", data-placement intact, non-(0,0) left/top retained, content has inert, trigger toBeFocused(). | @cross-browser |
| 2 | Pass-through interaction mid-exit | While content & scrim are mid-fade (opacity > 0), clicking an uncovered page <button> increments its click counter on the first click; pressing Tab moves from trigger to that button without focus trap recovery. | While popover is mid-fade over an underlying <button>, clicking at the popover's bounding box coordinates activates the underlying <button> (pointer-events: none) and does not focus the exiting popover. | chromium-e2e |
| 3 | Physical DOM removal after exit settles | After transition finishes: .ghost-dialog-content and .ghost-dialog-overlay have count 0 in DOM; focus remains on the control focused during/after close (never yanked back to trigger on unmount). | After transition finishes: .ghost-popover-content has count 0 in DOM; autoUpdate listeners detached; focus unchanged from where the user moved it during exit. | @cross-browser |
| 4 | Outside pointer dismissal | Clicking .ghost-dialog-overlay starts exit (data-state="closed"), restores trigger focus (including WebKit press completion without dropping to <body>), and unmounts both overlay and content after fade. | Clicking an outside <button> starts popover exit (data-state="closed"), leaves focus on the clicked <button> (toBeFocused()), and unmounts content after fade without pulling focus to trigger. | @cross-browser |
| 5 | Nested layers (Popover inside Dialog) | Open Dialog -> open portaled Popover inside -> first Escape immediately starts Popover exit & restores focus to Popover trigger inside Dialog; second immediate Escape (while Popover still exiting) starts Dialog exit & restores Dialog trigger focus. | Popover exits independently without blocking the enclosing Dialog's Escape dismissal or wedging trappedStack / layerStack. | @cross-browser |
| 6 | Reduced motion (prefers-reduced-motion) | Under emulateMedia({ reducedMotion: 'reduce' }): computed translate is none throughout exit, opacity fades over --ghost-motion-fade-duration (80ms), then unmounts cleanly. | Under reducedMotion: 'reduce': computed scale is 1 (no scale travel), opacity fades over 80ms, then unmounts cleanly. | chromium-e2e |
| 7 | Absent motion (0ms / headless / intensity: 0) | Headless Dialog without theme CSS (and themed Dialog under --ghost-motion-intensity: 0) unmounts content & overlay in the close frame with zero lingering [data-state="closed"] node. | Headless Popover without theme CSS (and themed Popover under --ghost-motion-intensity: 0) unmounts immediately on close. | chromium-e2e |
| 8 | Interrupted exit & rapid reopen | Close (Escape) -> mid-exit reopen (Enter on trigger): same DOM node (data-instance-id / WeakRef preserved) flips back to data-state="open", removes inert, re-locks scroll, re-traps Tab, and focuses inside Dialog. | Close (Escape) -> mid-exit click trigger: same DOM node flips to data-state="open", removes inert, restores pointer-events, keeps data-placement, and moves focus back inside Popover. | @cross-browser |
| 9 | Stale completion event after reopen | See exact observable contract below — reopened modal stays mounted, visible, focused, trapped, and scroll-locked after the interrupted exit's duration elapses and after a synthetic transitionend. | See exact observable contract below — reopened popover stays mounted, visible, positioned, and interactive after the interrupted exit's duration elapses and after a synthetic transitionend. | chromium-e2e |
| 10 | Inline mode (portal=false) & owner unmount | With :portal="false", exiting Dialog animates in-place and unmounts; unmounting parent wrapper mid-exit immediately removes portaled DOM, releases scroll lock, and clears background inert. | With :portal="false", exiting Popover animates in-place; unmounting parent wrapper mid-exit removes portaled DOM immediately with zero console errors. | chromium-e2e |
| 11 | Automated accessibility (axe) | @axe-core/playwright reports zero violations when open, while mid-exit (data-state="closed", inert), and after unmount. | @axe-core/playwright reports zero violations when open, while mid-exit (data-state="closed", inert), and after unmount. | chromium-e2e |
| 12 | Surface infinite & repeat animations | Dialog surface with animation: pulse 1s infinite unmounts immediately on close (or after its finite exit transition when paired) without hanging; finite animation: exit-fade 100ms 3 stays mounted for ~300ms then unmounts cleanly. | Popover surface with animation: pulse 1s infinite unmounts cleanly and detaches autoUpdate resources without hanging indefinitely; finite 100ms × 3 exit animation stays mounted through all 3 iterations before removal. | chromium-e2e |
For row 7, also exercise a zero-duration opacity change with a positive delay on the surface. Restore focus at logical close and assert that the inert surface stays mounted during the delay, then unmounts after completion.
Observable result when a stale completion event arrives after reopen
Test setup (executed for both modal GhostDialog and non-modal GhostPopover on a 300ms CSS exit transition):
- Open the overlay (
t = 0ms) and confirm focus is inside content. - Dismiss with
Escape(t = 10ms) and confirmdata-state="closed",inertis present on content, and trigger is focused (toBeFocused()). - Reopen before exit finishes (
t = 70ms) via trigger activation, then both dispatch a syntheticnew TransitionEvent('transitionend', { propertyName: 'opacity', bubbles: true })on the content element and wait350ms(past the original310msexit deadline and past the reverse-open transition completion).
Required observable result at t = 420ms:
- DOM & portal: Content (and
GhostDialogOverlayfor modal Dialog) remains connected insidedocument.body(toBeVisible()), with the exact same DOM element identity as before close,data-state="open", noinertattribute, and normalpointer-events. - Trigger & ARIA: Trigger reports
aria-expanded="true"anddata-state="open". - Focus & dismissal: Focus remains inside the overlay (
toBeFocused()on the initial focus target);Tabstays trapped insideGhostDialog; pressingEscapeonce cleanly dismisses the overlay on the first press. - Modal isolation (
GhostDialog): Viewport scroll remains locked and background siblings remaininert. - Events: No extra
update:open(false)orexitCompleteevent was emitted during or after the stale completion window.
Unit, SSR, theme CSS, and type tests
- Composable unit tests (
packages/vue/src/use-ghost-presence.test.ts):closed -> open -> exiting -> closedtransitions;getAnimations()path (multiple animations on element, finite multi-iteration animations such asiterations: 3, cancelledAbortError, ignoring descendantGhostSpinneranimations, excludingiterations: Infinity/ non-finiteendTime/playbackRate: 0animations on the surface itself both alone and alongside a finite exit transition, and the safety deadline for an animation paused after inspection, in wall-clock time at non-unitplaybackRate, re-armed when the rate is lowered mid-exit);getComputedStyle+transitionend/animationend/transitioncancelfallback path (including finiteanimationIterationCountscaling such as100ms×3->300msmax and334mssafety deadline, list cycling across comma-separated CSS properties, and excludinganimation-iteration-count: infinitefrom deadline calculation and completion events). WithgetAnimationsunavailable, testtransition: opacity 0ms 100ms: the surface is still mounted just before 100ms and unmounts on the matching end event at 100ms, or at the 134ms safety deadline if no event arrives. Withtransition: opacity 100ms, transform 300ms, the opacity end event leaves the surface mounted and the later transform end event completes the exit. With a zero delay and zero duration, assert unmount in the post-close flush. Also coverdisabled: true;attemptIdguard acrossopen -> close -> reopenandopen -> close -> reopen -> close; owner unmount mid-exit suppressingonExitComplete. - Component & host tests (
packages/vue/src/GhostPresence.test.ts,GhostDialog.test.ts,GhostPopover.test.ts,GhostDrawer.test.ts,GhostCommandPalette.test.ts,GhostDatePicker.test.ts,GhostHoverCard.test.ts): single-childcloneVNoderef merging, consumerinertpreservation, controlledopenignoringupdate:open(false)(never entering'exiting'), unpositioned floating close fast-path, and dev warning whenGhostPresencewraps a multi-root fragment withoutsetElement. - SSR & hydration (
packages/vue/src/overlay-ssr.test.ts,tests/integration/ssr-hydration.test.ts): Node SSR withoutwindowordocumentforGhostPresenceand updated hosts (defaultOpen: falseanddefaultOpen: true), plusexpectSsrHydrationparity. - Theme CSS integration (
tests/integration/ghost-dialog-theme-css.test.tsand peer overlay CSS tests): updateghost-dialog-theme-css.test.ts(which previously assertednot.toMatch(/\[data-state='closed'\]/)) to verify token-only[data-state='closed']exit rules, base geometry selectors decoupled from[data-state='open'],prefers-reduced-motion: reducecollapsing spatial transforms tonone/1, and zero hardcoded color/length/duration literals. - Compile-time type tests (
packages/vue/type-tests/): positive and// @ts-expect-errorfixtures forGhostPresenceprops/emits/slot props anduseGhostPresenceoptions/return types.
Documentation plan
When #417 implements the approved contract:
- Add
docs/components/presence.mdwith generated API tables (pnpm manifests:write+pnpm docs:api:writeforghost-presence.manifest.json), headless CSS exit examples,GhostPortalcomposition, and accessibility timing notes. - Add executable examples under
examples/presence/(basic.vue,portal.vue) and updatedocs/themes/motion.md("Overlay entry" -> "Overlay entry and exit") to document the symmetric[data-state='closed']exit recipes. - Update
Non-goalsandState modelprose in/specs/dialog,/specs/popover,/specs/drawer,/specs/hover-card, and/specs/command-paletteto reflectuseGhostPresenceretention during exit. - Register
presence.registry.json(pnpm registries:write) and playground motion/overlay exit exercises.
Compatibility and release impact
- Target release:
0.2.0(minorChangeset for@ghostvue/vueand@ghostvue/themesin#417; this specification PR is docs-only and adds no Changeset). - Backwards compatibility:
- Headless (
@ghostvue/vue): Consumers with no[data-state='closed']CSS transitions/animations observe0mscomputed duration and unmount in the post-close flush, preserving existing behavior and tests thatawait nextTick()on unstyled components. Consumers who already wrote[data-state='closed']transitions now see them play before unmount while focus, Escape,inert, and scroll lock still release immediately on logical close. - Themed (
@ghostvue/themes): Adopted overlay hosts gain120ms(80msunder reduced motion) exit transitions on close. Existing Playwright tests on themed overlays that assert DOM count0immediately after close will wait for unmount (toBeHidden()/toHaveCount(0)auto-retry) or run with Playwrightanimations: 'disabled'(already used by@visualsuites). - Existing
data-statehook:GhostDialogContent,GhostDialogOverlay,GhostDrawerContent, andGhostDrawerOverlaypreviously hardcodeddata-state="open"while mounted because unmount was synchronous; emittingdata-state="closed"during'exiting'completes the documentedopen | closedstate contract.
- Headless (
Resolved decisions
Zac authorized design sign-off on P1–P6 as proposed at commit 225f9fe09b1bbab8c03d88138c80ebdb171b6e01 (recorded in PR #488 on 2026-11-28). #417 remains blocked until the revised PR #488 merges to master:
- P1 — Public primitive surface and naming: Export both
GhostPresenceanduseGhostPresencefrom@ghostvue/vue(matching ADR 0003'sGhost*/useGhost*pair), with the minimal{ present, disabled }props/options surface and no imperative JS leave hook props. Approved by Zac as proposed at225f9fe0(PR #488, 2026-11-28). - P2 — First-release host scope for
#417: ShipGhostPresence+useGhostPresence, the shareddialog-shared.tsfamily (GhostDialog,GhostDrawer,GhostCommandPalette, plusGhostDatePickerContentcoordinate retention),GhostPopover, andGhostHoverCardtogether in#417; defer menus (DropdownMenu,ContextMenu,Menubar) until#418/#419settle and defer persistent-DOM listboxes (Select,Combobox) until#421settles. Approved by Zac as proposed at225f9fe0(PR #488, 2026-11-28). - P3 —
forceMountprop on overlay content parts: OmitforceMountfromGhostDialogContent/GhostPopoverContentin0.2.0because built-inuseGhostPresencehandles CSS transitions and animations automatically without extra props, keeping the public surface smaller. Approved by Zac as proposed at225f9fe0(PR #488, 2026-11-28). - P4 — Exiting surface isolation mechanism: Apply native HTML
inert(preserving consumer-ownedinertif already set) plus inlinepointer-events: noneon exiting content andpointer-events: noneon exiting modal backdrops, afteruseFocusScoperestores focus synchronously at logical close. Approved by Zac as proposed at225f9fe0(PR #488, 2026-11-28). - P5 — Floating positioning during exit: Keep
useFloatingbound to the mounted element until physical unmount (isPresent === false) so anchored overlays keep their coordinates,data-placement, and scroll tracking during the120msfade, while fast-pathing to immediate unmount if closed before initialisPositionedresolved. Approved by Zac as proposed at225f9fe0(PR #488, 2026-11-28). - P6 —
GhostDrawerContentexit duration token: Usevar(--ghost-motion-exit-duration)(120mswith accelerate easing) across all overlays per Motion's "exits run faster than enters" rule (250msenter ->120msexit). Approved by Zac as proposed at225f9fe0(PR #488, 2026-11-28).
Post-approval amendments
After the P1–P6 sign-off, review findings in PR #517 kept turning up narrower cases of restoring a component root's own mid-exit pointer-events writes. Maintainer zprue743 chose to narrow the contract instead (decision). This narrows the slot contract and changes no approved decision. It is not a new approval.
- Non-forwarding component roots. For a single component root that does not forward attributes,
GhostPresenceownspointer-events,inertand thedata-stateit injects from exit start to exit end. A component write to any of them during the exit is overridden until the exit ends (data-stateadded under the same decision after review comment 4729728067). On reopen, an injecteddata-statereturns toopen. Thepointer-eventscaptured at exit start comes back unless the reopen render wrote a value other thannone. Anyinertthe component set itself stays. A component that changespointer-eventsduring an exit re-applies its own value afterwards.GhostPresencedoes not read Vue component internals to recover such writes.