Preview Card
A hover preview of a link destination for sighted pointer and keyboard users.
The latest workflow revision was published by Ada Lovelace two hours ago.
Usage guidelines
- Use
PreviewCardas a non-interactive enhancement for a link destination, such as a member profile or a cited document. UsePopoverwhen opening the popup is the trigger's purpose or its content must be reachable on touch and with assistive technology. - Keep the link as the only accessible interface. The popup is not reachable on touch or by screen readers, so everything it shows also exists at the linked destination.
- Keep the popup free of buttons, links and fields. Users cannot move focus into it.
PreviewCardTriggerrenders a real link. Give it anhrefand visible link text, which also names it.- Several links can share one root through a handle from
createPreviewCardHandle. Each trigger passes its item aspayload, and the root's function child reads the payload of the hovered or focused link. - The default delays suit links in prose. Shorten
delayandcloseDelayon the trigger for dense lists where users scan many links in a row.
Anatomy
PreviewCardContent bundles the portal, positioner and styled popup and takes side, align and their offsets. Compose PreviewCardPortal, PreviewCardPositioner and PreviewCardPopup directly, with PreviewCardViewport, only when a surface needs more than those options.
Examples
Links sharing one preview
Two citations in a sentence share one root through a handle. Each link passes its document as payload.
The answer cites Refund policy.pdf and Shipping guide.md from the Customer support knowledge base.
Shorter delays in a list
A member list shares one root through a handle and sets shorter delay and closeDelay values on each trigger, so a single preview follows the pointer smoothly while scanning down the list.
Keyboard
| Key | Action |
|---|---|
| Tab | Focusing the link opens the preview after the trigger's delay. Moving focus away closes it. |
| Escape | Closes the preview. Focus stays on the link. |
API reference
PreviewCard
Groups all parts of a hover- and focus-triggered preview card for a link. Doesn't render its own HTML element.
Keep the preview non-interactive and duplicate any essential content at the linked destination, since touch and screen-reader users cannot reach it. Use Popover when opening the popup is the trigger's purpose or when its content must be accessible across input modes.
| Prop | Type | Default | Details |
|---|---|---|---|
defaultOpen | boolean | false | |
open | boolean | No default | |
onOpenChange | ((open: boolean, eventDetails: BasePreviewCard.Root.ChangeEventDetails) => void) | No default | |
onOpenChangeComplete | ((open: boolean) => void) | No default | |
actionsRef | React.RefObject<PreviewCardRootActions | null> | No default | |
handle | BasePreviewCard.Handle<Payload> | No default | |
children | PayloadChildRenderFunction<Payload> | React.ReactNode | No default | |
triggerId | string | null | No default | |
defaultTriggerId | string | null | No default | |
PreviewCardContent
A styled preview card surface bundled with a portal and positioner. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
sideOffset | number | OffsetFunction | 8 | |
children required | React.ReactNode | No default | |
className | string | ((state: PreviewCardPopupState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, PreviewCardPopupState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: PreviewCardPopupState) => React.CSSProperties | undefined) | No default | |
side | 'bottom' | 'inline-end' | 'inline-start' | 'left' | 'right' | 'top' | 'bottom' | |
align | 'center' | 'end' | 'start' | 'center' | |
alignOffset | number | OffsetFunction | 0 | |
| Attribute | Description |
|---|---|
data-open | Present when the preview card is open. |
data-closed | Present when the preview card is closed. |
data-starting-style | Present when the preview card begins animating in. |
data-ending-style | Present when the preview card is animating out. |
data-side | Values: Indicates which side the popup is positioned relative to the trigger. |
data-align | Values: Indicates how the popup is aligned relative to specified side. |
| Variable | Description |
|---|---|
--available-width | Values: The available width between the trigger and the edge of the viewport. |
--available-height | Values: The available height between the trigger and the edge of the viewport. |
--anchor-width | Values: The anchor's width. |
--anchor-height | Values: The anchor's height. |
--transform-origin | Values: The coordinates that this element is anchored to. Used for animations and transitions. |
--positioner-width | Values: The width of the preview card's positioner. It is important to set |
--positioner-height | Values: The height of the preview card's positioner. It is important to set |
PreviewCardPopup
A container for the preview card contents. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: PreviewCardPopupState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, PreviewCardPopupState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: PreviewCardPopupState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-open | Present when the preview card is open. |
data-closed | Present when the preview card is closed. |
data-starting-style | Present when the preview card begins animating in. |
data-ending-style | Present when the preview card is animating out. |
data-side | Values: Indicates which side the popup is positioned relative to the trigger. |
data-align | Values: Indicates how the popup is aligned relative to specified side. |
PreviewCardPortal
A portal element that moves the popup to a different part of the DOM. By default, the portal element is appended to <body>. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
keepMounted | boolean | false | |
container | HTMLElement | React.RefObject<HTMLElement | ShadowRoot | null> | ShadowRoot | null | No default | |
className | string | ((state: PreviewCardPortalState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, PreviewCardPortalState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: PreviewCardPortalState) => React.CSSProperties | undefined) | No default | |
PreviewCardPositioner
Positions the popup against the trigger. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
sideOffset | number | OffsetFunction | 8 | |
className | string | ((state: PreviewCardPositionerState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, PreviewCardPositionerState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: PreviewCardPositionerState) => React.CSSProperties | undefined) | No default | |
anchor | Element | React.RefObject<Element | null> | VirtualElement | (() => Element | VirtualElement | null) | null | No default | |
positionMethod | 'absolute' | 'fixed' | 'absolute' | |
side | 'bottom' | 'inline-end' | 'inline-start' | 'left' | 'right' | 'top' | 'bottom' | |
align | 'center' | 'end' | 'start' | 'center' | |
alignOffset | number | OffsetFunction | 0 | |
collisionBoundary | Boundary | 'clipping-ancestors' | |
collisionPadding | Padding | 5 | |
sticky | boolean | false | |
arrowPadding | number | 5 | |
disableAnchorTracking | boolean | false | |
collisionAvoidance | CollisionAvoidance | No default | |
| Attribute | Description |
|---|---|
data-open | Present when the preview card is open. |
data-closed | Present when the preview card is closed. |
data-anchor-hidden | Present when the anchor is hidden. |
data-side | Values: Indicates which side the popup is positioned relative to the trigger. |
data-align | Values: Indicates how the popup is aligned relative to specified side. |
| Variable | Description |
|---|---|
--available-width | Values: The available width between the trigger and the edge of the viewport. |
--available-height | Values: The available height between the trigger and the edge of the viewport. |
--anchor-width | Values: The anchor's width. |
--anchor-height | Values: The anchor's height. |
--transform-origin | Values: The coordinates that this element is anchored to. Used for animations and transitions. |
--positioner-width | Values: The width of the preview card's positioner. It is important to set |
--positioner-height | Values: The height of the preview card's positioner. It is important to set |
PreviewCardTrigger
A link that opens the preview card. Renders an <a> element.
| Prop | Type | Default | Details |
|---|---|---|---|
handle | BasePreviewCard.Handle<Payload> | No default | |
payload | Payload | No default | |
delay | number | 600 | |
closeDelay | number | 300 | |
className | string | ((state: PreviewCardTriggerState) => string | undefined) | No default | |
render | ComponentRenderFn<React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, PreviewCardTriggerState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: PreviewCardTriggerState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-popup-open | Present when the corresponding preview card is open. |
PreviewCardViewport
A viewport for displaying content transitions. This component is only required if one popup can be opened by multiple triggers, its content changes based on the trigger, and switching between them is animated. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
children | React.ReactNode | No default | |
className | string | ((state: PreviewCardViewportState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, PreviewCardViewportState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: PreviewCardViewportState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-current | Applied to the direct child of the viewport when no transitions are present or the new content when it's entering. |
data-previous | Applied to the direct child of the viewport that contains the exiting content when transitions are present. |
data-activation-direction | Values: Indicates the direction from which the popup was activated. This can be used to create directional animations based on how the popup was triggered. Contains space-separated values for both horizontal and vertical axes. |
data-transitioning | Indicates that the viewport is currently transitioning between old and new content. |
data-instant | Values: Present if animations should be instant. |
| Variable | Description |
|---|---|
--popup-width | The width of the parent popup. This variable is placed on the 'previous' container and stores the width of the popup when the previous content was rendered. It can be used to freeze the dimensions of the popup when animating between different content. |
--popup-height | The height of the parent popup. This variable is placed on the 'previous' container and stores the height of the popup when the previous content was rendered. It can be used to freeze the dimensions of the popup when animating between different content. |
createPreviewCardHandle
Creates a new handle to connect a PreviewCard.Root with detached PreviewCard.Trigger components.
Returns
BasePreviewCard.Handle<Payload>| Member | Type | Description |
|---|---|---|
open required | (triggerId: string) => void | Opens the preview card and associates it with the trigger with the given id. This method should only be called in an event handler or an effect (not during rendering). |
close required | () => void | Closes the preview card. This method should only be called in an event handler or an effect (not during rendering). |
isOpen required | boolean | Whether the preview card is currently open. Returns |