Web · Components
HoverCard
Preview card that opens when hovering a link or a name: a user profile, product summary, link preview.
4 exports
Live example
Preview
This design was made by @ayse .
Code
Events
- Events appear here when you interact with the preview.
Import
Preview card that opens when hovering a link or a name: a user profile, product summary, link preview. Only for extra info; what's in the card must also be reachable another way. For short text use Tooltip, and for a panel that opens on click use Popover.
- The mouse opens it after a short delay; it stays open when the mouse moves onto the card, so links in the card can be clicked.
- Opens on keyboard focus, closes with Esc.
contentcan be an (async) function: called on first open, a placeholder shows until the result arrives, and the result is cached; hundreds of triggers on the page make no requests.- Mobile: opens on long press and closes on tapping elsewhere; a normal tap opens the link.
- Opens in the top layer (
popover) and is positioned with CSS anchor positioning; the card is not added to the DOM until first needed.
Examples
HoverCardContent
typeContent of the card: an element or a function called once on first open. The function can return a Promise (e.g. fetching user info from the server); a placeholder is shown until the result arrives, and the result is cached.
HoverCardTouch
typeHow the card opens on touch screens.
longPress: opens on long press; a normal tap opens the link.none: never opens on touch.
HoverCardProps
interfaceProps of the HoverCard component.
| Name | Type | Default | Description |
|---|---|---|---|
trigger | ReactElement | Element that opens the card; usually a link (user name, product name). The element's own job (following the link) is not broken. | |
content | HoverCardContent | Content. See HoverCardContent. | |
side? | Placement | "auto" | Position relative to the trigger. See Placement. |
openDelay? | number | 500 | Open delay after the mouse enters (ms). |
closeDelay? | number | 250 | Close delay after the mouse leaves (ms). If the mouse moves onto the card in this time, it stays open. |
touch? | HoverCardTouch | "longPress" | How it opens on touch screens. See HoverCardTouch. |
open? | boolean | Is it open when controlled? | |
defaultOpen? | boolean | false | Is it initially open when uncontrolled? |
onOpenChange? | (open: boolean) => void | Called with the new state when it opens or closes. | |
className? | string | Classes added to the card (e.g. w-80 for width). | |
effect? | EffectProp | Effect or effects of the card (e.g. "beam", "glow"). If omitted, UIProvider appearance.defaults.hoverCard.effect. See BuiltinEffect. |