@akhatmirzo/ui

HoverCard

A preview card shown when the pointer rests on a link — a profile, a product, link details.

Kutubxona muallifi — @akhatmirzo.

Import

import { HoverCard } from '@akhatmirzo/ui';

When to use

  • Preview what's behind a link — a user profile, a product, a document. Users get a quick "what is this?" answer without leaving the page.
  • Supplementary content only. The card doesn't open on touch screens and screen readers may not read it — the trigger should be a real link, and the same information should live on the page it points to.
  • A short text hint? Use a Tooltip.
  • Buttons or a form inside? Use a click-to-open Popover.

Anatomy

PartWhat it does
HoverCardState and delays: openDelay, closeDelay, open
HoverCard.TriggerThe link (an <a> by default; asChild for your own element)
HoverCard.ContentThe panel: same look as Popover, portal, positioning, size
<HoverCard openDelay={400}>
  <HoverCard.Trigger asChild>
    <a href="/u/akhatmirzo">@akhatmirzo</a>
  </HoverCard.Trigger>
  <HoverCard.Content side="bottom" align="start">
    …profile…
  </HoverCard.Content>
</HoverCard>

The card opens 500ms after the pointer arrives and closes 200ms after it leaves — it doesn't pop up when the pointer just passes by, and there's time to move onto the card. It also opens when the trigger receives keyboard focus.

Sizes

size is sm (240px) or md (320px, the default). Pass a className for any other width.

Placement

side is top, right, bottom (default) or left; align is start, center (default) or end. The panel sits 6px from the trigger and flips to the opposite side near the screen edge.

Don't hide important information

Phones and tablets have no hover — HoverCard never opens there. Keep key information such as prices, statuses or errors visible on the page itself.

Props

HoverCard

PropTypeDefaultDescription
openDelaynumber500Delay before opening after the pointer arrives, ms
closeDelaynumber200Delay before closing after the pointer leaves, ms
openboolean—Whether it is open (controlled)
defaultOpenboolean—Open initially
onOpenChange(open: boolean) => void—Called on open/close

HoverCard.Content

Also accepts the rest of the Radix HoverCard.Content props (alignOffset, avoidCollisions ...), <div> attributes and ref.

PropTypeDefaultDescription
size'sm' | 'md''md'Width: 240 / 320px
side'top' | 'right' | 'bottom' | 'left''bottom'Preferred side
align'start' | 'center' | 'end''center'Alignment along the trigger
sideOffsetnumber6Gap to the trigger, px
collisionPaddingnumber8Minimum distance from the screen edge, px
containerHTMLElement | null—Portal container (defaults to document.body)

Data attributes

AttributeWhereValue
data-statetrigger, panelopen · closed
data-sidepaneltop · right · bottom · left
data-sizepanelsm · md

Accessibility

  • Supplementary only. The card is not announced and focus doesn't move into it — its content must also be available on the page the link opens.
  • Keyboard. The card opens when the trigger gets focus and closes when focus leaves; Esc closes it too.
  • Touch screens. It doesn't open on touch — a tap follows the link itself.
  • No interactive content (buttons, forms) inside — keyboard users can't reach it. Use a Popover instead.

On this page