Loading component…
Loading component…
A preview of what a link or name points to
To reuse this local React demo, copy all files from the Code tab into the same folder, then import HoverCard from ./hover-card.
import { HoverCard } from "@/components/ui/hover-card";
export function AgentName({ agent }: { agent: { id: string; name: string; role: string; status: string } }) {
return (
<HoverCard
width={288}
content={
<div>
<strong>{agent.name}</strong>
<p>{agent.role} · {agent.status}</p>
<a href={`/agents/${agent.id}`}>Open agent</a>
</div>
}
>
<a href={`/agents/${agent.id}`}>{agent.name}</a>
</HoverCard>
);
}| Name | Type | Default | Description |
|---|---|---|---|
| content | ReactNode | What the card shows – the card brings its padding, edge and shadow, you bring the inside. Empty or null: only the trigger is rendered | |
| children | ReactElement | Exactly one element that takes a ref and focus – usually a link. Its own handlers run first; one that calls preventDefault keeps the card out of it. The card is a <div> right after it – inside running text, use a <div> rather than a <p> around it, as HTML doesn't allow a <div> in a <p> | |
| side | "bottom" \| "top" \| "right" \| "left" | "bottom" | Where it opens; flips to the other side when that has more room |
| align | "start" \| "center" \| "end" | "start" | Which edges of card and trigger line up; switches when the card would stick out. start and end follow the reading direction |
| offset | number | 8 | Gap to the trigger in px |
| openDelay | number | 600 | How long the pointer rests (or the keyboard focus stays) before it opens, in ms – passing over a list opens nothing |
| closeDelay | number | 300 | How long it stays after the pointer leaves trigger and card, in ms |
| width | number \| string | The card's width; by default it fits its content, up to 320px | |
| open / onOpenChange | boolean / (open) => void | Controls it from outside; leave open out and it opens on its own | |
| disabled | boolean | Never opens | |
| className | string | A class for the card |
The grace area: on the way from the trigger into the card, the pointer may cross the gap (and the corridor to the card's far corners) without it closing
Only one card at a time; it lives in the top layer (popover), so no overflow cuts it, follows its trigger on scroll and flips to stay on screen – a tall card scrolls
Touch never opens it: a tap follows the link, and a tap anywhere else closes one that is open
Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"
@import "tailwindcss"; in your main CSS file.