EXEPERTAI LAB

Research alpha

Time Machine
EXEPERTAI LAB
GALLERY / COLLECTION
← Browse Astryx gallery
HoverCard·hook·@astryxdesign/core

useHoverCard

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.

Open in Playground @astryxdesign/core/HoverCard

Signature

Call shape
useHoverCard(options: HoverCardOptions = {}): HoverCardReturn
Parameters
NameType and behavior
placement'above' | 'below' | 'start' | 'end' · optional · default 'above'
Position relative to the trigger. Logical: start/end resolve against the popover's own inherited direction (RTL mirrors in pure CSS).
alignment'start' | 'center' | 'end' · optional · default 'center'
Alignment along the placement axis. Logical: start/end resolve against the popover's own inherited direction (RTL mirrors in pure CSS).
delaynumber · optional · default 300
Delay before showing the hover card on hover, in milliseconds.
hideDelaynumber · optional · default 200
Delay before hiding after mouse or focus leaves, in milliseconds.
focusTrigger'auto' | 'always' | 'never' · optional · default 'auto'
When focus should open the hover card. auto only attaches focus listeners to naturally focusable elements.
touchTrigger'auto' | 'tap' | 'none' · optional · default 'auto'
What a tap does where there is no hover. auto opens on tap unless the trigger performs an action of its own; tap always opens; none never opens on touch.
isEnabledboolean · optional · default true
Whether hover and focus triggers are enabled.
labelstring
Accessible 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).
isOpenboolean
Controlled open state. true force-shows, false force-hides, undefined lets hover/focus manage visibility.
isDefaultOpenboolean · optional · default false
Whether the hover card should be shown on mount.
onShow() => void
Callback fired when the hover card becomes visible.
onHide() => void
Callback fired when the hover card is hidden.
Returns
NameType and behavior
refRefCallback<HTMLElement>
Combined ref that sets both position and interaction on the same trigger element.
positionRefRefCallback<HTMLElement>
Ref for the positioning anchor element. Use when position and interaction live on different elements.
interactionRefRefCallback<HTMLElement>
Ref for the hover/focus interaction element. Use with positionRef for split trigger patterns.
anchorIdstring
CSS anchor name for advanced positioning cases.
describedBystring
ID to compose into aria-describedby on the trigger.
renderHoverCard(children: ReactNode, props?: Omit<ContextRenderProps, 'positioning'>) => ReactNode
Render function for the anchor-positioned hover card content. The positioning opt-out is excluded: the hover card always derives its position from placement/alignment.
show() => void
Imperatively show the hover card immediately.
hide() => void
Imperatively hide the hover card immediately.

Showcases and examples

2 documented examples

Hover Card

A hover card that shows a user profile preview when hovering over a trigger button. Starts open for preview.

Preview loads on approachPreview loads on approach
Exact source · hover-card-showcase
// Copyright (c) Meta Platforms, Inc. and affiliates.

'use client';

import {HoverCard} from '@astryxdesign/core/HoverCard';
import {Button} from '@astryxdesign/core/Button';
import {Stack} from '@astryxdesign/core/Layout';
import {Text, Heading} from '@astryxdesign/core/Text';
import {Avatar} from '@astryxdesign/core/Avatar';

export default function HoverCardShowcase() {
  return (
    <HoverCard
      placement="above"
      content={
        <Stack direction="vertical" gap={2} style={{width: 240}}>
          <Stack direction="horizontal" gap={2} vAlign="center">
            <Avatar name="Jane Doe" size="lg" />
            <Stack direction="vertical" gap={0}>
              <Heading level={5}>Jane Doe</Heading>
              <Text type="supporting" color="secondary">
                Software Engineer
              </Text>
            </Stack>
          </Stack>
          <Text type="body" color="secondary">
            Building great products with great people.
          </Text>
        </Stack>
      }>
      <Button label="@janedoe" variant="ghost" />
    </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.

  • Use for rich content previews such as user profiles, entity summaries, and link previews.
  • Prefer the HoverCard component for standard trigger-content pairs; use the hook for custom trigger patterns.
  • Use for simple text hints: use Tooltip or useTooltip instead.