GhostPopover specification
Status: Approved and implemented (GhostPopover on master, GHO-78 complete).
Purpose and user problems
GhostPopover displays a floating, non-modal disclosure surface anchored to a trigger control. It composes @ghostvue/vue's overlay primitives (useDismissableLayer, useFloating, GhostPortal, useFocusScope, useControllableState, and useGhostId) so applications get reliable positioning, portaling, Escape/outside-pointer dismissal, and focus entry/return without reimplementing layer stacking or Floating UI wiring.
Non-goals
- Modal dialog behavior (
aria-modal="true", backdrop, orTabfocus trapping). Those belong to a futureGhostDialog. - Tooltip hover/focus delay timing (
aria-describedby/role="tooltip"). Those belong toGhostTooltip. - Menu or listbox keyboard navigation (
aria-haspopup="menu", arrow-key roving, typeahead). Those belong toGhostDropdownMenuandGhostSelect. - Decorative arrow/caret elements or open/close CSS transition hooks beyond
data-stateanddata-placement.
Public API
Parts and exports
Headless exports from @ghostvue/vue:
GhostPopover(root state and context provider; renderless)GhostPopoverTrigger(anchor and toggle button)GhostPopoverContent(positioned, dismissable floatingrole="dialog"surface)GhostPopoverClose(convenience close button inside content)useGhostPopover(composable returning reactive open state, controls, and trigger/content IDs)- Types:
GhostPopoverProps,GhostPopoverSlotProps,GhostPopoverTriggerElement,GhostPopoverTriggerProps,GhostPopoverTriggerExposed,GhostPopoverContentElement,GhostPopoverContentProps,GhostPopoverContentExposed,GhostPopoverCloseElement,GhostPopoverCloseProps,GhostPopoverCloseExposed,UseGhostPopoverOptions,UseGhostPopoverReturn,GhostPopoverContext
Themed exports from @ghostvue/themes:
GhostPopover,GhostPopoverTrigger,GhostPopoverContent,GhostPopoverClose(plus re-exported types and styles viadefault.css)
Props and configuration
GhostPopover (root)
| Prop | Type | Default | Contract |
|---|---|---|---|
open | boolean | undefined | undefined | Controlled open state. Omit for uncontrolled mode. |
defaultOpen | boolean | false | Initial open state in uncontrolled mode. |
GhostPopoverTrigger
| Prop | Type | Default | Contract |
|---|---|---|---|
as | GhostPopoverTriggerElement (Component | string) | 'button' | Element tag or component (for example GhostButton). |
disabled | boolean | false | Prevents toggling when true. Uses native disabled on <button> / button components and aria-disabled="true" on non-button tags. |
Native attributes and listeners fall through to the rendered root element.
GhostPopoverContent
| Prop | Type | Default | Contract |
|---|---|---|---|
as | GhostPopoverContentElement (Component | string) | 'div' | Element tag or component for the dialog surface. |
placement | Placement | 'bottom' | Preferred placement relative to the trigger. |
offset | OffsetOptions | boolean | undefined | undefined | Distance or axis offsets passed to useFloating. |
flip | boolean | FlipOptions | true | Flip to an opposite side when overflowing. |
shift | boolean | ShiftOptions | true | Shift along the cross axis to stay in view. |
strategy | Strategy ('absolute' | 'fixed') | 'absolute' | CSS positioning strategy passed to useFloating. |
portal | boolean | true | Renders content through GhostPortal when true, or inline when false. |
portalTo | GhostPortalTarget | 'body' | Teleport target passed to GhostPortal when portal is true. |
Native attributes and listeners fall through to the floating content element.
GhostPopoverClose
| Prop | Type | Default | Contract |
|---|---|---|---|
as | GhostPopoverCloseElement (Component | string) | 'button' | Element tag or component. |
disabled | boolean | false | Disables activation when true. |
v-model contracts
GhostPopover owns open via useControllableState:
open(modelValue: false— uses explicitopen+update:openper Vue 3v-model:openconvention).- When
openisundefined(omitted), internal state starts atdefaultOpenand updates automatically on trigger, Escape, outside pointerdown, or close activations while still emittingupdate:open. - When
openisboolean,update:openis emitted and the consumer owns the state update.
Events, callbacks, slots, and exposed methods
GhostPopoveremitsupdate:openwith[open: boolean].GhostPopoverdefault slot receives{ open: boolean, close: () => void }.GhostPopoverTrigger,GhostPopoverContent, andGhostPopoverCloseexpose{ element: HTMLElement | null, focus(options?: FocusOptions): void, blur(): void }matchingGhostButton. When:as="GhostButton"is used,elementresolves to the underlying<button>element.
State model
- Two binary states:
'closed'and'open'. GhostPopoverContentrenders withv-ifonuseGhostPresence, notv-show. Logical close removes it fromuseDismissableLayer'slayerStackanduseFocusScopeimmediately; the node stays mounted withdata-state="closed",inert,pointer-events: none, and itsuseFloatingcoordinates only while its CSS exit motion runs, then unmounts and stopsautoUpdate(presence spec).data-state="open" | "closed"is set onGhostPopoverTriggerandGhostPopoverContent.data-placementis written onGhostPopoverContentbyuseFloatingonce the resolved placement is computed.GhostPopoverContentkeepsvisibility: hiddeninline untiluseFloating().isPositionedbecomestrue, preventing any first-frame flash at(0, 0).
Loading, empty, disabled, read-only, and error states
GhostPopoverTrigger and GhostPopoverClose support disabled. A disabled trigger ignores click and keyboard activation.
Consumer data
GhostPopover holds no domain collections and never mutates consumer props.
Accessibility contract
Follows WAI-ARIA APG disclosure / non-modal dialog guidance:
Semantics and relationships
GhostPopoverTriggerrenderstype="button"(whenas="button"),id(fromuseGhostId, overridable by consumerid),aria-haspopup="dialog",aria-expanded="true" | "false",aria-controls="<contentId>",data-part="trigger", anddata-state="open" | "closed".GhostPopoverContentrendersid(matchingaria-controls, overridable by consumerid),role="dialog",tabindex="-1",data-part="content",data-state="open", andaria-labelledby="<triggerId>"by default unless the consumer providesaria-labeloraria-labelledby. Noaria-modal="true".GhostPopoverCloserenderstype="button"(whenas="button"),data-part="close".
Keyboard interaction
| Key | Where | Behavior |
|---|---|---|
Enter / Space | GhostPopoverTrigger | Toggles open. Non-button as elements also support Enter / Space with role="button" and tabindex="0". |
Escape | Topmost open GhostPopoverContent | Closes the topmost popover layer via useDismissableLayer and restores focus to the trigger. |
Enter / Space | GhostPopoverClose | Closes the popover and restores focus to the trigger. |
Tab / Shift+Tab | Inside GhostPopoverContent | Moves freely without trapping (useFocusScope with trapped: false). |
Focus behavior
- Reuses
useFocusScopewith{ trapped: false, autoFocus: true, restoreFocus }(no second focus implementation). - Focus activation waits until the content is both teleported (if
portalis enabled) and positioned (isPositioned === true, i.e.,visibility: hiddenremoved) sogetTabbableElements()and.focus()succeed reliably. - On open, focus moves to
[data-autofocus]if present and focusable, else the first tabbable descendant insideGhostPopoverContent, elseGhostPopoverContentitself (tabindex="-1"). - On close via Escape,
GhostPopoverClose, trigger toggle, or outside click on a non-focusable target, focus restores to the trigger (the active element at open). Outside clicks targeting another focusable element allow focus to move to that target without yanking it back.
Rendering and customization
GhostPopoverTrigger(data-part="trigger",data-state),GhostPopoverContent(ghost-popover-content,data-part="content",data-state,data-placement),GhostPopoverClose(data-part="close").- Styled
@ghostvue/themesCSS adds minimal dialog surface tokens under@layer ghostvue-themeusing--ghost-elevation-3-*,--ghost-radius-lg,--ghost-border-hairline-width,--ghost-surface-fg,--ghost-space-inset-md, focus ring tokens, and@media (forced-colors: active). No new tokens added.
Environment behavior
SSR and hydration
useGhostIdprovides deterministic SSR-safe IDs.- Closed popovers render only the trigger (
v-if="false"for content). defaultOpen: trueSSR renders the dialog inline viaGhostPortalwithout accessingwindowordocument;useFloating,useDismissableLayer, anduseFocusScopeonly attach browser behavior insideonMounted.
Mobile and touch
useDismissableLayerlistens to capture-phasepointerdown, supporting mouse, touch, and pen input consistently.GhostPopoverContentshifts within viewport edges by default (shift: true,flip: true).
Performance
useFloating(autoUpdate) anduseDismissableLayerdocument listeners are active only whileGhostPopoverContentis open and mounted. Closed popovers register zero global listeners and zero observers.
Composition
useGhostPopover+useControllableState+useGhostIdfor state and IDs.GhostPortalfor teleportation.useFloatingfor anchor positioning, collision handling,data-placement, andisPositioned.useDismissableLayerfor stacked Escape and outside-pointer dismissal with triggerignore.useFocusScope(trapped: false) for focus entry and restoration.
Test plan
- Unit tests (
packages/vue/src/GhostPopover.test.ts,use-floating.test.ts): controlled/uncontrolledopen,aria-*anddata-*attrs,aria-labelledbyfallback vs override,isPositioned&visibility: hiddenfirst-paint guard,portalvsportal=false,asprop (includingGhostButton),GhostPopoverClose, focus entry (first tabbable + container fallback) and return on close, Escape, outsidepointerdown, trigger toggle without close-then-reopen,v-ifunmount removing the layer fromlayerStack, nested popovers closing one at a time. - SSR test (
packages/vue/src/overlay-ssr.test.ts): Node environment with nowindow/document, closed anddefaultOpen: trueSSR rendering. - Theme CSS integration test (
tests/integration/ghost-popover-theme-css.test.ts): zero hard-coded colors/px/time literals inghost-popover.css. - Browser & Axe E2E tests (
tests/e2e/popover.spec.ts,tests/e2e/docs-examples.spec.ts): click and keyboard open/close, Escape focus return, outside click dismissal, viewport-edge flip, nested popover one-layer-at-a-time dismissal, popover inside an offsetposition: relativeparent landing at the expected offset from its anchor, production docs page demo verification, and@axe-core/playwrightzero violations. Nested popover dismissal and a portaled popover's Tab order inside a modal trap are tagged@cross-browserand also run in Firefox and WebKit.
Documentation plan
docs/components/popover.mdled by the themed sharing-settings showcase (examples/popover/share-settings.vue), with headless and themed executable examples (examples/popover/basic.vue,examples/popover/themed.vue), API tables, and non-modal dialog accessibility guidance.- Sidebar entry in
apps/docs/.vitepress/docs-nav.tsand roadmap status update indocs/roadmap.md. - Machine-readable manifests generated via
pnpm manifests:write.
Compatibility and release impact
- Additive minor change (
minorChangeset) for@ghostvue/vueand@ghostvue/themes. - Additive
isPositionedproperty onUseFloatingReturn(non-breaking).
GHO-78 acceptance traceability
Audit (GHO-78): implementation on master satisfies the issue scope. Gaps closed in #61 and follow-up PRs; this issue confirms coverage via the tests below rather than new public API.
| Criterion | Implementation | Proof |
|---|---|---|
Controlled / uncontrolled open | useControllableState in useGhostPopover / GhostPopover | GhostPopover.test.ts — uncontrolled and controlled cases |
| Trigger toggle | GhostPopoverTrigger click / Enter / Space | GhostPopover.test.ts, tests/e2e/popover.spec.ts |
| Disabled trigger | Native disabled on <button>; no open on click / Enter | GhostPopover.test.ts — disabled prop |
| Outside interaction | useDismissableLayer + trigger ignore | GhostPopover.test.ts — outside pointerdown |
Escape dismissal | useDismissableLayer stack | GhostPopover.test.ts, tests/e2e/popover.spec.ts |
| Focus entry / restoration | useFocusScope (trapped: false) | GhostPopover.test.ts — open/close and outside-focusable clicks |
| Positioning / collision | useFloating (flip, shift, data-placement) | GhostPopover.test.ts — isPositioned; tests/e2e/popover.spec.ts — viewport flip |
| Portal | GhostPortal default body | GhostPopover.test.ts — portal / portal=false |
| Nesting | dismissable-layer-stack | GhostPopover.test.ts — nested Escape; tests/e2e/popover.spec.ts |
| SSR | useGhostId, mount guards in composables | overlay-ssr.test.ts |
| Not Menu / Tooltip / Dialog | aria-haspopup="dialog", role="dialog", no aria-modal | GhostPopover.test.ts — APG attributes; semantics guard test |
Open architectural questions
None.