ADR 0011: Overlay primitives
- Status: accepted
- Date: 2026-11-12
- Decision owners: repository maintainers
- Relates to: ADR 0003 (naming), ADR 0004 (headless layering), focus.md (
useFocusScope), dependencies.md (runtime dependency policy)
Context
Upcoming overlay components (GhostPopover, GhostTooltip, GhostDropdownMenu, GhostSelect, and GhostDialog) share three headless requirements that do not belong inside any single widget:
- Dismissable layering: closing only the topmost open overlay on
Escapeorpointerdownoutside the layer, while excluding trigger elements so clicking a toggle trigger does not close onpointerdownand immediately reopen onclick. - Anchor positioning: placing a floating surface relative to an anchor element (or virtual element) with
offset,flip, andshiftcollision handling, updating on scroll/resize/element-resize, and writingdata-placementfor directional styling hooks. - Portaling: rendering overlay content outside clipping ancestors via Vue
<Teleport>without breaking SSR or hydration.
Per ADR 0003 and focus.md, shared low-level composables omit the useGhost* component prefix (useDismissableLayer, useFloating), while the public teleport component uses the Ghost prefix (GhostPortal). All three primitives stay headless inside @ghostvue/vue and never import @ghostvue/themes.
Decision
Add three headless overlay primitives to @ghostvue/vue:
1. Layering model (useDismissableLayer and GhostPortal)
useDismissableLayer(el, options)coordinates nested overlays through a module-levellayerStackinside@ghostvue/vue, matching the stacking model used byuseFocusScope'strappedStack.- Capture-phase
pointerdownand bubble-phasekeydownlisteners attach todocumentonly after mount and only whilelayerStackis non-empty; they detach as soon as the last layer deactivates or unmounts. Listening in the bubble phase forkeydownensures descendants inside the layer (such as an<input>) can callevent.preventDefault()onEscapebefore layer dismissal runs. - Only the topmost layer on
layerStackhandlesEscape(when notdefaultPreventedorisComposing) and outsidepointerdown. If the topmost layer setsdisableEscapeordisableOutsidePointer, it blocks lower layers from dismissing underneath it rather than letting events fall through. - Escape-only layers (currently only
GhostTooltipContent, through an internal registration that is not exported) joinlayerStackforEscapeordering but are skipped for outsidepointerdown: a press inside one is ignored, and any other press is handled by the next ordinary layer beneath. They are also ignored when a trappeduseFocusScopechecks for focus in an upper layer, so a tooltip never blocks click-away dismissal or opens a hole in a modal trap. - Elements in
ignore(such as the trigger button) are checked alongsideelviacomposedPath()(withcontains()fallback) so pressing them never counts as an outside interaction. - When nested DOM layers mount in the same render cycle (where Vue runs child
onMountedbefore parentonMounted), descendant layers remain ordered above their ancestor layers onlayerStack. GhostPortalwraps Vue 3.5's<Teleport>withto,disabled, anddefer. Teleportation is disabled untilonMountedruns (and whenevertoisnull) so SSR and initial client hydration render identical inline HTML without readingdocumentor requiringssrContext.teleports.
2. Positioning dependency (@floating-ui/dom in useFloating)
useFloating(anchor, floating, options)wraps@floating-ui/dom'scomputePosition,autoUpdate,offset,flip, andshift.@floating-ui/domis added as an exact-pinned runtime dependency of@ghostvue/vueand kept external inpackages/vue/vite.config.tsso consumer bundlers tree-shake unused middleware and deduplicate the package.- Per dependencies.md:
- Capability: viewport and overflow-ancestor collision detection (
flip,shift,offset),VirtualElementsupport,ResizeObserver+ scroll/layout-shift tracking (autoUpdate), and browser edge cases across CSS transforms,offsetParentchains, RTL, and Shadow DOM. - Why local / platform APIs are insufficient: CSS Anchor Positioning does not yet cover all supported browsers or expose reactive JS
data-placementand coordinate state. Hand-rolling overflow-ancestor walking,offsetParentcompensation,flip/shiftmath, andResizeObserverloops would produce a fragile, high-maintenance clone of@floating-ui/dom. - Tree-shaking and bundle impact:
@floating-ui/domis side-effect-free ESM; consumers who do not importuseFloatingpay 0 bytes. ImportinguseFloatingpulls incomputePosition,autoUpdate,offset,flip, andshift(~22.1 kB minified / ~7.2 kB gzip for the@floating-ui/domsubset; ~23.5 kB minified / ~7.7 kB gzip together with theuseFloatingwrapper). - License, maintenance, security: MIT-licensed, zero install scripts, actively maintained standard across headless UI libraries, and no browser-global side effects at module evaluation time.
- SSR/browser behavior:
computePositionandautoUpdaterun only insideonMounted; SSR setup returns{ x: 0, y: 0, placement, isPositioned: false }without touchingwindowordocumentand writesdata-placementonly on mounted clients. - First-paint visibility guard:
useFloatingexposesisPositioned, which staysfalseuntil the firstcomputePositionresolves and resets when the floating layer closes, swaps targets, or unmounts (without flickering on option-only updates). Overlay consumers keep floating surfacesvisibility: hiddenuntilisPositionedistrueso they never flash at0,0.
- Capability: viewport and overflow-ancestor collision detection (
3. Single-copy module stack constraint
layerStackinuseDismissableLayer(liketrappedStackinuseFocusScope) is scoped per loaded copy of@ghostvue/vue.- If an application loads two separate copies of
@ghostvue/vue(for example, un-deduplicated versions or isolated micro-frontends), each copy maintains its ownlayerStackand Escape/outside-pointer coordination will not span across copies.
Alternatives considered
Hand-rolled positioning engine. Rejected. Reimplementing getBoundingClientRect ancestor-overflow clipping, offsetParent transforms, and autoUpdate observers would add significant maintenance and browser-quirk risk while violating dependencies.md in reverse (reinventing a well-scoped, MIT-licensed standard).
Global window / document registry to share layerStack across multiple copies of GhostVue. Rejected for v1. Writing undocumented properties onto window or document introduces hidden global state and version-skew hazards between incompatible LayerRecord shapes. Consumers should deduplicate @ghostvue/vue; revisit only if real multi-bundle micro-frontend deployments require a versioned DOM/event coordination protocol.
Per-layer document listeners without a shared dispatcher. Rejected. Individual capture listeners can observe out-of-order stack mutations if a consumer reacts synchronously, whereas a single top-only dispatcher guarantees exactly one layer receives onDismiss per event and detaches cleanly at zero layers.
Consequences
@ghostvue/vuegainsuseDismissableLayer,useFloating, andGhostPortalplus their TypeScript types (DismissReason,UseDismissableLayerOptions,UseFloatingOptions,UseFloatingReturn,GhostPortalProps,GhostPortalTarget).@ghostvue/vuegains an exact-pinned runtime dependency on@floating-ui/dom.packages/vue/manifests/ghost-portal.manifest.jsonis generated viapnpm manifests:write.- Future overlay components (
GhostTooltip,GhostPopover,GhostDropdownMenu,GhostSelect,GhostDialog) compose these primitives rather than introducing widget-specific portal, positioning, or outside-dismissal logic.
Compatibility implications
Additive minor release on pre-release @ghostvue/vue (0.0.0). Existing public APIs are unchanged. SSR output stays deterministic with zero window/document access during setup. Consumers must ensure @ghostvue/vue is deduplicated to one runtime copy when nesting dismissable layers across packages.