GitHubGitHub
← All components
Overlays / component

Hover card

A rich preview that opens once the pointer rests on a trigger, with a grace period for crossing onto the card and no focus trapping.

PointerKeyboard focusAligned endTouch

Assigned to — rest the pointer on the name, or tab to it.

<HoverCard>  {#snippet trigger()}<a href="/people/ana">Ana Ruiz</a>{/snippet}  <p>Platform team — maintains api-gateway.</p></HoverCard>

Installation

pnpm add @chanrg/4ui

Import the stylesheet once, at the root of your app:

import '@chanrg/4ui/styles.css';

Usage

import { HoverCard } from '@chanrg/4ui';<HoverCard>  {#snippet trigger()}<a href="/people/ana">Ana Ruiz</a>{/snippet}  <p>Platform team — maintains api-gateway.</p></HoverCard>

Aligned to the end

Align the card to the end of the trigger when it sits near the right edge of a column.

Assigned to — the card lines up with the end of the name.

<HoverCard align="end" openDelay={0}>  {#snippet trigger()}<a href="/people/ana">Ana Ruiz</a>{/snippet}  …card body…</HoverCard>

API reference

Props

PropTypeDefaultDescription
openboolean ($bindable)falseWhether the card is showing.
openDelaynumber300Milliseconds the pointer must rest on the trigger before opening.
closeDelaynumber150Grace period after the pointer leaves, so it can cross onto the card.
alignstart | endstartHorizontal alignment against the trigger.
trigger / childrenSnippetThe thing being previewed, and the preview itself.
onopenchange(open) => voidFires on every open and close.

CSS variables

VariableDescription
--4ui-surfacePrimary component surface.
--4ui-textPrimary foreground color.
--4ui-borderDefault control and panel border.
--4ui-shadow-floatElevation of the floating card.
--4ui-z-popoverStacking order of the portalled panel.

Accessibility

  • Never a dialog: focus is neither trapped nor moved, and the card is announced through the trigger’s aria-describedby.
  • Keyboard focus opens it immediately — a user who tabbed to the trigger has already committed, so there is no dwell delay.
  • The pointer path is gated behind (hover: hover), so a tap on a touch device just activates the link underneath.
  • Escape and an outside pointer dismiss the card.

Dependencies

Icon, dismiss/portal/floating primitives