Cómo funciona
The card is placed in layout pixels against the closest element marked data-ds-boundary, or the viewport: it flips above when there is no room below, shifts sideways to stay inside, and moves its arrow by the same amount so it still points at the trigger. A transparent bridge covers the gap so the pointer can reach the card.
Úsalo para
- Previewing a person, a link or a record without leaving the page.
- Optional context that sighted pointer users benefit from.
Busca otra opción cuando
- Essential information or actions: they must also be reachable another way, since touch has no hover.
- Short text labels: use a tooltip.
Uso
import { HoverCard } from './HoverCard.jsx'
export function Mention() {
return (
<HoverCard label="Profile of Mara Lin" content={<ProfilePreview id="mara" />}>
<a href="/people/mara">@mara.lin</a>
</HoverCard>
)
}Propiedades
| Propiedad | Tipo | Por defecto | Qué hace |
|---|---|---|---|
children | ReactElement | — | The trigger, usually a link; it receives aria-describedby while the card is open. |
content | ReactNode | — | The card body. Use inline elements (span) when the trigger sits inside a paragraph. |
label | string | — | Accessible name of the card. |
openDelay | number | 500 | Pointer rest time in ms before opening; keyboard focus waits at most 300. |
closeDelay | number | 220 | Grace period in ms after the pointer leaves. |
side | 'bottom' | 'top' | 'bottom' | Preferred side; flips when there is no room. |
defaultOpen | boolean | false | Open on first render. |
Accesibilidad
- The card opens on keyboard focus as well as hover, and the trigger gets aria-describedby pointing at it.
- The card is a non-modal role dialog placed right after the trigger, so Tab moves into its buttons; leaving the card closes it.
- Escape closes the card and returns focus to the trigger.
- Touch input does not open it; the link keeps working as a link.
- With reduced motion the card only fades and the delay underline appears without animating.
Movimiento
Open after 500ms with a linear underline fill; enter 220ms cubic-bezier(0.32, 1.2, 0.5, 1) from 0.96 scale and 4px, scaled from the arrow; leave 130ms.
Añádelo a tu proyecto
Copia la instrucción en Codex o Claude Code. El agente lee el código publicado, te muestra lo que va a escribir y añade el componente junto a los tuyos.
HoverCard.jsxhover-card.csstokens.cssREADME.md
Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

