GhostHoverCard specification
Status: Approved for minimal GhostHoverCard (GHO-100). Visual baselines use pnpm test:visual:docker.
Purpose and user problems
GhostHoverCard shows a rich preview panel on pointer hover or keyboard focus of a trigger, with open and close delays so users can move the pointer onto interactive content without the panel vanishing. It composes @ghostvue/vue overlay primitives (useFloating, useDismissableLayer, GhostPortal, useControllableState, and useGhostId) so applications get reliable positioning, portaling, delay timing, Escape/outside dismissal, and non-modal dialog semantics without reimplementing Floating UI or WCAG 1.4.13 hover/focus behavior.
Typical uses include profile previews, link cards, and contextual summaries with links or secondary actions.
Non-goals
- Click-to-toggle disclosure on the trigger (
GhostPopover). - Modal dialog behavior (
aria-modal, scroll lock, focus trapping, or inert background). Those belong toGhostDialog. - Brief supplemental
role="tooltip"hints without interactive descendants. Those belong toGhostTooltip. - Menu or listbox keyboard navigation inside the card beyond normal tab order.
- Decorative arrow/caret elements or open/close CSS transition hooks beyond
data-stateanddata-placement. - Shared skip-delay coordination across adjacent cards (
GhostTooltipProvideris tooltip-specific).
Public API
Parts and exports
Headless exports from @ghostvue/vue:
GhostHoverCard(root state, delays, and context provider; renderless)GhostHoverCardTrigger(hover/focus anchor)GhostHoverCardContent(positioned floating non-modalrole="dialog"surface)useGhostHoverCard(composable returning reactive open state, controls, and trigger/content IDs)- Types:
GhostHoverCardProps,GhostHoverCardSlotProps,GhostHoverCardTriggerElement,GhostHoverCardTriggerProps,GhostHoverCardTriggerExposed,GhostHoverCardContentElement,GhostHoverCardContentProps,GhostHoverCardContentExposed,UseGhostHoverCardOptions,UseGhostHoverCardReturn,GhostHoverCardContext
Themed exports from @ghostvue/themes:
GhostHoverCard,GhostHoverCardTrigger,GhostHoverCardContent(plus re-exported types and styles viadefault.css)
Props and configuration
GhostHoverCard (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 (discouraged; for tests/SSR). |
openDelay | number | 700 | Milliseconds before showing after hover or focus begins. |
closeDelay | number | 300 | Milliseconds before hiding after hover/focus leaves the trigger and card. |
closeOnEscape | boolean | true | When true, Escape dismisses via useDismissableLayer. |
GhostHoverCardTrigger
| Prop | Type | Default | Contract |
|---|---|---|---|
as | GhostHoverCardTriggerElement (Component | string) | 'button' | Element tag or component (for example GhostButton). |
disabled | boolean | false | Prevents show scheduling when true. Uses native disabled on <button> / button components and aria-disabled="true" otherwise. |
Native attributes and listeners fall through to the rendered root element.
GhostHoverCardContent
| Prop | Type | Default | Contract |
|---|---|---|---|
as | GhostHoverCardContentElement (Component | string) | 'div' | Element tag or component for the card 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.
v-model contracts
GhostHoverCard owns open via useControllableState:
open(modelValue: false— uses explicitopen+update:openper Vue 3v-model:openconvention).- When
openisundefined(omitted), internal state starts atdefaultOpenand updates on hover/focus timers, pointer/focus leave, Escape, or outside pointerdown while still emittingupdate:open. - When
openisboolean,update:openis emitted and the consumer owns the state update.
Events, callbacks, slots, and exposed methods
GhostHoverCardemitsupdate:openwith[open: boolean].GhostHoverCarddefault slot receives{ open: boolean, close: () => void }.GhostHoverCardTriggerandGhostHoverCardContentexpose{ 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'. GhostHoverCardContentrenders withv-ifonuseGhostPresence, notv-show. Logical close leavesuseDismissableLayer's layer stack at once; the card stays mounted withdata-state="closed",inert, andpointer-events: none(overriding itsautodefault) only while its CSS exit motion runs, then unmounts and stopsautoUpdate(presence spec).data-state="open" | "closed"is set onGhostHoverCardTriggerandGhostHoverCardContent.data-placementis written onGhostHoverCardContentbyuseFloatingonce the resolved placement is computed.GhostHoverCardContentkeepsvisibility: hiddeninline untiluseFloating().isPositionedbecomestrue, preventing any first-frame flash at(0, 0).
Loading, empty, disabled, read-only, and error states
GhostHoverCardTrigger supports disabled. A disabled trigger does not schedule show on hover or focus.
Consumer data
GhostHoverCard holds no domain collections and never mutates consumer props.
Accessibility contract
Follows WAI-ARIA APG non-modal dialog / disclosure-on-hover guidance and WCAG 1.4.13 (Content on Hover or Focus):
Semantics and relationships
GhostHoverCardTriggerrenderstype="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". Noaria-describedby(content may be rich and interactive).GhostHoverCardContentrendersid(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". Interactive descendants are allowed.
Keyboard interaction
| Key | Where | Behavior |
|---|---|---|
Escape | Document while open | Closes when closeOnEscape is true; focus stays on the trigger. |
Tab | Trigger and content | Normal tab order; focus inside content keeps the card open. |
Opening on hover does not move focus. Opening on focus follows delay timing without auto-moving focus into the card.
Focus behavior
- Pointer hover open does not move focus.
- The card remains open while the trigger has pointer hover or focus, while the pointer is over the card, or while focus is inside the card.
- Closing via
Escape, outside pointerdown, leaving all hover/focus targets, or thecloseDelaytiming elapses after all leave.
Assistive technology expectations
- The trigger exposes expanded/collapsed state and names the associated dialog surface via
aria-controls/aria-labelledby.
Rendering and customization
GhostHoverCardTrigger(data-part="trigger",data-state),GhostHoverCardContent(ghost-hover-card-content,data-part="content",data-state,data-placement,data-hoverable).- Themed
@ghostvue/themesCSS adds an elevation-3 surface (between tooltip and popover density) using--ghost-*semantic tokens. Content usespointer-events: autoso links and buttons inside the card receive pointer input.
Environment behavior
SSR and hydration
useGhostIdprovides deterministic SSR-safe IDs.- Closed cards render only the trigger (
v-if="false"for content). defaultOpen: trueSSR renders the card inline viaGhostPortalwithout accessingwindowordocument;useFloatingand dismiss listeners attach only after mount.- Hydration covered by
expectSsrHydrationintegration test.
Mobile and touch
- Pointer show/hide uses
pointerenter/pointerleave(with grace delay). useFloating(shift: true,flip: true) keeps cards in view.
Performance
useFloating(autoUpdate) is active only whileGhostHoverCardContentis open and mounted.- Open/close timers clear on unmount; no global listeners remain when closed.
Composition
useGhostHoverCard+useControllableState+useGhostIdfor state and IDs.GhostPortalfor teleportation.useFloatingfor anchor positioning, collision handling,data-placement, andisPositioned.useDismissableLayeron content for Escape and outside-pointer dismissal (trigger ignored).- Root owns delay timers, pointer/focus/content hover and content focus tracking, and timer cleanup on unmount.
Test plan
- Unit tests (
packages/vue/src/GhostHoverCard.test.ts): controlled/uncontrolledopen, delay timers (Vitest fake timers),aria-haspopup/aria-expanded/aria-controls,role="dialog", interactive content hover,data-*attrs,isPositionedvisibility guard,portalvsportal=false, disabled trigger,Escapedismissal, outside-pointer dismissal, timer/listener cleanup on unmount, parent ignoringupdate:open,asprop includingGhostButton,v-ifunmount stoppingautoUpdate. - SSR test (
packages/vue/src/overlay-ssr.test.ts): closed anddefaultOpen: trueSSR rendering in Node withoutwindow/document. - SSR hydration test (
tests/integration/ghost-hover-card-ssr.test.ts):expectSsrHydrationfor closed anddefaultOpenfixtures. - Theme CSS integration test: zero hard-coded colors/px/time literals in
ghost-hover-card.css. - Browser & Axe E2E tests (
tests/e2e/ghost-hover-card.spec.ts,tests/e2e/docs-examples.spec.ts): hover/focus show with delay, grace delay on leave, pointer onto interactive content,Escapedismissal, disabled trigger, and zero Axe violations.
Documentation plan
docs/components/hover-card.mdwith headless and themed executable examples (examples/hover-card/basic.vue,examples/hover-card/themed.vue), API tables, and hover/focus accessibility guidance.- Playground
HoverCardReference.vuesection with unique copy for strict locators. - 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.
Open architectural questions
None for the minimal scope. Styling-hook contract beyond data-part / data-state remains deferred (GHO-38).