GhostTooltip specification
Status: Approved for minimal GhostTooltip (GHO-79).
Purpose and user problems
GhostTooltip shows a brief, supplemental description on pointer hover or keyboard focus without stealing focus or implying required information. It composes @ghostvue/vue overlay primitives (useFloating, GhostPortal, useControllableState, and useGhostId) so applications get reliable positioning, portaling, open/close delay timing, and assistive-technology wiring without reimplementing Floating UI or WCAG 1.4.13 hover/focus behavior.
Typical uses include truncated table headers and icon-only actions in future GhostDataTable work.
Non-goals
- Modal, dialog, or popover disclosure (
aria-haspopup,aria-expanded, interactive panels, focus entry). Those belong toGhostPopover/GhostDialog. - Required field hints, form validation text, or any content that must be read to complete a task.
- Interactive tooltip content (links, buttons, inputs). Consumers must not place focusable or operable descendants inside
GhostTooltipContent. - Menu / listbox semantics or roving focus inside the tooltip.
- Decorative arrow/caret elements or open/close CSS transition hooks beyond
data-stateanddata-placement. - Click-to-toggle activation on the trigger (tooltips are hover/focus driven).
Public API
Parts and exports
Headless exports from @ghostvue/vue:
GhostTooltip(root state, delays, and context provider; renderless)GhostTooltipTrigger(hover/focus anchor)GhostTooltipContent(positioned floatingrole="tooltip"surface)useGhostTooltip(composable returning reactive open state, controls, and trigger/content IDs)- Types:
GhostTooltipProps,GhostTooltipSlotProps,GhostTooltipTriggerElement,GhostTooltipTriggerProps,GhostTooltipTriggerExposed,GhostTooltipContentElement,GhostTooltipContentProps,GhostTooltipContentExposed,UseGhostTooltipOptions,UseGhostTooltipReturn,GhostTooltipContext
Themed exports from @ghostvue/themes:
GhostTooltip,GhostTooltipTrigger,GhostTooltipContent(plus re-exported types and styles viadefault.css)
Props and configuration
GhostTooltip (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 snapshots). |
delayDuration | number | 700 | Milliseconds before showing after hover or focus begins. |
closeDelay | number | 300 | Milliseconds before hiding after hover/focus leaves the trigger and content. |
disableHoverableContent | boolean | false | When true, hides immediately on leave (closeDelay ignored) and disables content hover. |
GhostTooltipTrigger
| Prop | Type | Default | Contract |
|---|---|---|---|
as | GhostTooltipTriggerElement (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.
GhostTooltipContent
| Prop | Type | Default | Contract |
|---|---|---|---|
as | GhostTooltipContentElement (Component | string) | 'div' | Element tag or component for the tooltip surface. |
placement | Placement | 'top' | 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
GhostTooltip 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, orEscapewhile still emittingupdate:open. - When
openisboolean,update:openis emitted and the consumer owns the state update.
Events, callbacks, slots, and exposed methods
GhostTooltipemitsupdate:openwith[open: boolean].GhostTooltipdefault slot receives{ open: boolean }.GhostTooltipTriggerandGhostTooltipContentexpose{ 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'. GhostTooltipContentrenders withv-if="open", notv-show, so closed tooltips unmount cleanly from the DOM anduseFloating'sautoUpdate.data-state="open" | "closed"is set onGhostTooltipTrigger; open content usesdata-state="open".data-placementis written onGhostTooltipContentbyuseFloatingonce the resolved placement is computed.GhostTooltipContentkeepsvisibility: hiddeninline untiluseFloating().isPositionedbecomestrue, preventing any first-frame flash at(0, 0).
Loading, empty, disabled, read-only, and error states
GhostTooltipTrigger supports disabled. A disabled trigger does not schedule show on hover or focus.
Consumer data
GhostTooltip holds no domain collections and never mutates consumer props.
Accessibility contract
Follows WAI-ARIA APG Tooltip pattern and WCAG 1.4.13 (Content on Hover or Focus):
Semantics and relationships
GhostTooltipTriggerrenderstype="button"(whenas="button"),id(fromuseGhostId, overridable by consumerid),aria-describedbymerging consumer-provided ids with the tooltip content id while open (deduped),data-part="trigger", anddata-state="open" | "closed". Noaria-expandedoraria-haspopup.GhostTooltipContentrendersid(matchingaria-describedby, overridable by consumerid),role="tooltip", notabindex,data-part="content",data-state="open", and must not contain focusable or interactive descendants.
Keyboard interaction
| Key | Where | Behavior |
|---|---|---|
Escape | Document while open | Closes immediately (hideImmediate) when the tooltip is the topmost open overlay layer; does not move focus. |
Tab | GhostTooltipTrigger | Normal tab order; focus scheduling opens the tooltip after delay. |
Tooltip content is not in the tab order and must not receive focus.
Focus behavior
- Opening a tooltip does not move focus.
- The tooltip remains open while either the trigger has pointer hover or focus.
- Closing via
Escape, leaving both hover and focus, or thecloseDelaytiming elapses after all leave.
Assistive technology expectations
- While open, the trigger's accessible description includes tooltip text via
aria-describedby. - Tooltips are supplemental; they must not be the only source of a required name or description.
Rendering and customization
GhostTooltipTrigger(data-part="trigger",data-state),GhostTooltipContent(ghost-tooltip-content,data-part="content",data-state,data-placement).- Themed
@ghostvue/themesCSS adds a compact elevation surface using--ghost-elevation-2-*,--ghost-radius-md,--ghost-border-hairline-width,--ghost-surface-fg, and--ghost-space-inset-sm.pointer-events: noneby default;data-hoverableon content enablespointer-events: autofor WCAG hoverable movement unlessdisableHoverableContentis set.
Environment behavior
SSR and hydration
useGhostIdprovides deterministic SSR-safe IDs.- Closed tooltips render only the trigger (
v-if="false"for content). defaultOpen: trueSSR renders the tooltip inline viaGhostPortalwithout accessingwindowordocument;useFloatingand documentkeydownattach only insideonMounted.
Mobile and touch
- Pointer show/hide uses
pointerenter/pointerleave(with grace delay). useFloating(shift: true,flip: true) keeps tooltips in view.
Performance
useFloating(autoUpdate) is active only whileGhostTooltipContentis open and mounted.- Open/close timers clear on unmount; no global listeners remain when closed.
Composition
useGhostTooltip+useControllableState+useGhostIdfor state and IDs.GhostPortalfor teleportation.useFloatingfor anchor positioning, collision handling,data-placement, andisPositioned.- Root owns delay timers, pointer/focus/content hover tracking,
hideImmediate, and timer cleanup on unmount. GhostTooltipContentjoins the shared dismissable-layer stack (useDismissableLayer's internal escape-only registration) while open, soEscapedismisses only the topmost open overlay. A tooltip inside a dialog or popover closes on the firstEscape; the nextEscapereaches the layer beneath. Escape-only layers never take part in outside-pointer dismissal (presses outside pass through to the layer beneath; presses on the tooltip are not "outside" for it) and never claim focus above a modal focus trap. A separate per-tooltipdocumentlistener was rejected because listener registration order decides which handler runs first, so localpreventDefault()cannot coordinate dismissal reliably.
Test plan
- Unit tests (
packages/vue/src/GhostTooltip.test.ts): controlled/uncontrolledopen, delay timers (Vitest fake timers),aria-describedbywhile open,role="tooltip",data-*attrs,isPositionedvisibility guard,portalvsportal=false, disabled trigger,Escapedismissal and ordering above dialogs/popovers (inline and portaled), consumer-canceledEscape, timer/listener cleanup on unmount,asprop includingGhostButton,v-ifunmount stoppingautoUpdate. - SSR test (
packages/vue/src/overlay-ssr.test.ts): closed anddefaultOpen: trueSSR rendering in Node withoutwindow/document. - Theme CSS integration test: zero hard-coded colors/px/time literals in
ghost-tooltip.css. - Browser & Axe E2E tests (
tests/e2e/ghost-tooltip.spec.ts,tests/e2e/docs-examples.spec.ts): hover/focus show with delay, grace delay on leave,Escapedismissal, disabled trigger, viewport positioning, and zero Axe violations.tests/e2e/tooltip-layers.spec.tscovers tooltips inside a modal dialog (inline and portaled, controlled state) and a popover: oneEscapeper layer, real focus, outside-pointer pass-through, and Axe with overlays open and closed.
Documentation plan
docs/components/tooltip.mdwith headless and themed executable examples (examples/tooltip/basic.vue,examples/tooltip/themed.vue), API tables, and supplemental-description accessibility guidance.- Playground
TooltipReference.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.
Related primitives
GhostTooltipProvider(GHO-118) coordinates open-delay skipping between adjacent tooltips. See GhostTooltipProvider specification.