Hover card
Guests love Room 311 for a quiet weekend.
npx shadcn add @klarhimmel/hover-card @klarhimmel/text-linkCopy for AIExamples
Basic
Person
Controlled
DetailsAbout, usage, props and more
A preview of where a link goes, shown on hover and on keyboard focus, never the only copy.
When to use
Use for
A short preview of where a link goes: a room, a person, a rate.
Not for
Anything only available in the card. Touch screens never open it. Actions. Use Popover.
Pairs with
Text link, Avatar.
Preview
Guests love Room 311 for a quiet weekend.
Hover the link, or Tab to it: the preview opens on focus too. Escape closes it.
Import
Import
- Files
- hover-card.tsx, text-link.tsx, in components/klarhimmel/ui/. With it: button, theme, utils. npm: radix-ui.
- Render in
- Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.
- Limit
- Overlays render into the Theme root with position: fixed. A transform on an ancestor re-parents fixed (a dialog centres in the wrapper) and overflow: hidden clips menus. Render <Theme> at the app root, outside any transformed wrapper.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
trigger | ReactElement | required | The link or button that opens it. One element: it receives the card's description and keeps its own name. |
children | ReactNode | required | The preview. Plain content only: no buttons or links, because pointer and keyboard users cannot reach into it, and a touch screen never shows it. |
open | boolean | - | Controlled or uncontrolled. |
defaultOpen | boolean | - | Controlled or uncontrolled. |
onOpenChange | (open: boolean) => void | - | Controlled or uncontrolled. |
openDelay | number | 500 | Milliseconds before it opens and before it closes. Default 500 and 200. |
closeDelay | number | 200 | Milliseconds before it opens and closes. |
align | 'start' | 'center' | 'end' | 'center' | Where it sits against the trigger. |
className | string | - | Extra classes, merged after the component's own. |
Accessibility
| Key | Does |
|---|---|
Tab | Focusing the link opens the card; leaving closes it |
Escape | Closes it |
Enter | Follows the link, as always |
While open the card is the trigger's aria-describedby. It holds plain content: nothing in it can be reached by keyboard.
Accessibility