Hover Card
Rich previews that open on hover or focus.
Installs @floating-ui/react-dom and motion.
Installation
npx shadcn@latest add https://neonkit.heyaadi.com/r/hover-card.jsonUsage
import { HoverCard, HoverCardContent, HoverCardTrigger } from "@/components/ui/hover-card"
<HoverCard>
<HoverCardTrigger href="/people/mara">@mara</HoverCardTrigger>
<HoverCardContent>
Mara Okafor · Design engineer, Lisbon
</HoverCardContent>
</HoverCard>Examples
Link preview
side="top" and a shorter openDelay for inline links in running text.
Side and align
Cards to the right of a list, aligned to the top of each name. The light follows the side.
API reference
HoverCard
Holds the open state and the timers. Renders no element of its own.
| Prop | Type | Default |
|---|---|---|
openDelay | numberMilliseconds the pointer rests on the trigger, or keyboard focus stays, before the card opens. | 500 |
closeDelay | numberMilliseconds before closing after the pointer leaves, enough to cross onto the card. | 200 |
open | booleanControlled open state. | None |
defaultOpen | booleanInitial state when uncontrolled. | false |
onOpenChange | (open: boolean) => voidCalled when hover, focus, Escape or an outside click changes the state. | None |
HoverCardTrigger
Renders a link. Also accepts every native anchor attribute.
| Prop | Type | Default |
|---|---|---|
asChild | booleanMerges hover behaviour onto its single child, e.g. your router's Link. | false |
HoverCardContent
The card, portaled and positioned with floating-ui. Accepts native div attributes; it's w-72 with p-4 until you override them.
| Prop | Type | Default |
|---|---|---|
side | "top"Preferred side. Flips when there's no room. | "bottom" |
align | "start"Alignment along that side. | "center" |
sideOffset | numberGap from the trigger in px. | 8 |
color | NeonColorPalette name or hex. Without it the card takes the trigger's color, then --neon-accent, then cyan. | inherited |
Accessibility
- Opens on mouse hover and on keyboard focus of the trigger. Touch is ignored, so a tap just follows the link.
- The card stays open while the pointer is over it, and while the trigger keeps keyboard focus.
- While open, the trigger's aria-describedby points at the card, so screen readers announce its text as a description.
- Escape closes it without moving focus.
- Content inside the card isn't in the tab order after the trigger. Keep anything essential reachable elsewhere, as you would for a tooltip.