useHoverCard @astryx-svelte/core v0.3.0 · HoverCard

Usage

Headless hook for hover-triggered floating cards. Builds on useLayer with hover/focus intent detection, configurable delays, safe hover behavior, and accessible aria-describedby linking. Use for rich previews on hover when you need full control over the trigger or rendered content.
ts
import { HoverCard } from '@astryx-svelte/core';

Best practices

GuidancePractices
DoUse for rich content previews such as user profiles, entity summaries, and link previews.
DoPrefer the HoverCard component for standard trigger-content pairs; use the hook for custom trigger patterns.
Don'tUse for simple text hints: use Tooltip or useTooltip instead.

Parameters

ParameterTypeDefaultDescription
placement 'below' | 'above' | 'end' | 'start''above'Position relative to the trigger. Logical: start/end resolve against the popover's own inherited direction (RTL mirrors in pure CSS).
alignment 'end' | 'start' | 'center''center'Alignment along the placement axis. Logical: start/end resolve against the popover's own inherited direction (RTL mirrors in pure CSS).
delay number300Delay before showing the hover card on hover, in milliseconds.
hideDelay number200Delay before hiding after mouse or focus leaves, in milliseconds.
focusTrigger 'auto' | 'always' | 'never''auto'When focus should open the hover card. auto only attaches focus listeners to naturally focusable elements.
isEnabled booleantrueWhether hover and focus triggers are enabled.
label stringAccessible name for the hover card popup. When provided, the popup is exposed as a named role="dialog"; when omitted, it falls back to role="group" (a group may validly be unnamed).
isOpen booleanControlled open state. true force-shows, false force-hides, undefined lets hover/focus manage visibility.
isDefaultOpen booleanfalseWhether the hover card should be shown on mount.
onShow () => voidCallback fired when the hover card becomes visible.
onHide () => voidCallback fired when the hover card is hidden.

Returns

FieldTypeDefaultDescription
ref (node: HTMLElement | null) => voidCombined ref that sets both position and interaction on the same trigger element.

Svelte has no ref prop. Reach the element with an attachment through the spread props; bind:this on a component yields the instance rather than its element.Upstream declares RefCallback<HTMLElement>.

positionRef (node: HTMLElement | null) => voidRef for the positioning anchor element. Use when position and interaction live on different elements.

Element references are attachments here. The port returns an Attachment<HTMLElement> named attach…; spread it onto the element instead of assigning a ref.Upstream declares RefCallback<HTMLElement>.

interactionRef (node: HTMLElement | null) => voidRef for the hover/focus interaction element. Use with positionRef for split trigger patterns.

Element references are attachments here. The port returns an Attachment<HTMLElement> named attach…; spread it onto the element instead of assigning a ref.Upstream declares RefCallback<HTMLElement>.

anchorId stringCSS anchor name for advanced positioning cases.
describedBy stringID to compose into aria-describedby on the trigger.
renderHoverCard (children: string | Snippet, props?: Omit<ContextRenderProps, 'positioning'>) => string | SnippetRender function for the anchor-positioned hover card content. The positioning opt-out is excluded: the hover card always derives its position from placement/alignment.

A Svelte hook cannot return markup. This hook returns state only; render its companion component and pass the hook’s value to it.Upstream declares (children: ReactNode, props?: Omit<ContextRenderProps, 'positioning'>) => ReactNode.

show () => voidImperatively show the hover card immediately.
hide () => voidImperatively hide the hover card immediately.

Examples

Common configurations, variations, and states.
useHoverCard — Profile Preview
Custom profile preview using useHoverCard with direct trigger and render control.