Preview Card
A popup that appears when a link is hovered, showing a preview for sighted users.
View as MarkdownThe principles of good typography remain in the digital age.
Usage guidelines
- Popup content should reflect the link destination: Avoid placing unique or essential information in the popup unless it is also available on the linked page, so all users can access the same information. Preview cards are a visual enhancement for sighted mouse and keyboard users and are not accessible to touch or screen reader users.
Anatomy
Import the component and assemble its parts:
import { PreviewCard } from '@base-ui/react/preview-card';
<PreviewCard.Root>
<PreviewCard.Trigger />
<PreviewCard.Portal>
<PreviewCard.Backdrop />
<PreviewCard.Positioner>
<PreviewCard.Popup>
<PreviewCard.Arrow />
</PreviewCard.Popup>
</PreviewCard.Positioner>
</PreviewCard.Portal>
</PreviewCard.Root>Examples
Detached triggers
A preview card can be controlled by a trigger located either inside or outside the <PreviewCard.Root> component.
For simple, one-off interactions, place the <PreviewCard.Trigger> inside <PreviewCard.Root>, as shown in the example at the top of this page.
However, if defining the preview card’s content next to its trigger is not practical, you can use a detached trigger.
This involves placing the <PreviewCard.Trigger> outside of <PreviewCard.Root> and linking them with a handle created by the PreviewCard.createHandle() function.
const demoPreviewCard = PreviewCard.createHandle();
<PreviewCard.Trigger handle={demoPreviewCard} href="#">
Link
</PreviewCard.Trigger>
<PreviewCard.Root handle={demoPreviewCard}>
...
</PreviewCard.Root>The principles of good typography remain in the digital age.
Multiple triggers
A single preview card can be opened by multiple trigger elements.
You can achieve this by using the same handle for several detached triggers, or by placing multiple <PreviewCard.Trigger> components inside a single <PreviewCard.Root>.
<PreviewCard.Root>
<PreviewCard.Trigger href="#">Trigger 1</PreviewCard.Trigger>
<PreviewCard.Trigger href="#">Trigger 2</PreviewCard.Trigger>
...
</PreviewCard.Root>const demoPreviewCard = PreviewCard.createHandle();
<PreviewCard.Trigger handle={demoPreviewCard} href="#">
Trigger 1
</PreviewCard.Trigger>
<PreviewCard.Trigger handle={demoPreviewCard} href="#">
Trigger 2
</PreviewCard.Trigger>
<PreviewCard.Root handle={demoPreviewCard}>
...
</PreviewCard.Root>The preview card can render different content depending on which trigger opened it.
This is achieved by passing a payload to the <PreviewCard.Trigger> and using the function-as-a-child pattern in <PreviewCard.Root>.
The payload can be strongly typed by providing a type argument to the createHandle() function:
const demoPreviewCard = PreviewCard.createHandle<{ title: string }>();
<PreviewCard.Trigger handle={demoPreviewCard} payload={{ title: 'Trigger 1' }} href="#">
Trigger 1
</PreviewCard.Trigger>
<PreviewCard.Trigger handle={demoPreviewCard} payload={{ title: 'Trigger 2' }} href="#">
Trigger 2
</PreviewCard.Trigger>
<PreviewCard.Root handle={demoPreviewCard}>
{({ payload }) => (
<PreviewCard.Portal>
<PreviewCard.Positioner sideOffset={8}>
<PreviewCard.Popup>
{payload !== undefined && (
<span>
Preview card opened by {payload.title}
</span>
)}
</PreviewCard.Popup>
</PreviewCard.Positioner>
</PreviewCard.Portal>
)}
</PreviewCard.Root>Controlled mode with multiple triggers
You can control the preview card’s open state externally using the open and onOpenChange props on <PreviewCard.Root>.
This allows you to manage the preview card’s visibility based on your application’s state.
When using multiple triggers, you have to manage which trigger is active with the triggerId prop on <PreviewCard.Root> and the id prop on each <PreviewCard.Trigger>.
Note that there is no separate onTriggerIdChange prop.
Instead, the onOpenChange callback receives an additional argument, eventDetails, which contains the trigger element that initiated the state change.
Discover typography, design, or art.
Animating the Preview Card
You can animate a preview card as it moves between different trigger elements. This includes animating its position, size, and content.
Position and Size
To animate the preview card’s position, apply CSS transitions to the left, right, top, and bottom properties of the Positioner part.
To animate its size, transition the width and height of the Popup part.
Content
The preview card also supports content transitions. This is useful when different triggers display different content within the same preview card.
To enable content animations, wrap the content in the <PreviewCard.Viewport> part.
This part provides features to create direction-aware animations.
It renders a div with a data-activation-direction attribute (left, right, up, or down) that indicates the new trigger’s position relative to the previous one.
Inside the <PreviewCard.Viewport>, the content is further wrapped in divs with data attributes to help with styling:
data-current: The currently visible content when no transitions are present or the incoming content.data-previous: The outgoing content during a transition.
You can use these attributes to style the enter and exit animations.
Discover typography, design, or art.
API reference
Root
Groups all parts of the preview card. Doesn’t render its own HTML element.
defaultOpenbooleanfalse
- Name
- Description
Whether the preview card is initially open.
To render a controlled preview card, use the
openprop instead.- Type
boolean | undefined- Default
false
openboolean—
- Name
- Description
Whether the preview card is currently open.
- Type
boolean | undefined
onOpenChangefunction—
- Name
- Description
Event handler called when the preview card is opened or closed.
- Type
| (( open: boolean, eventDetails: PreviewCard.Root.ChangeEventDetails, ) => void) | undefined
actionsRefReact.RefObject<PreviewCard.Root.Actions | null>—
- Name
- Description
A ref to imperative actions.
unmount: Unmounts the preview card popup.close: Closes the preview card imperatively when called.
- Type
| React.RefObject<PreviewCard.Root.Actions | null> | undefined
defaultTriggerIdstring | null—
- Name
- Description
ID of the trigger that the preview card is associated with. This is useful in conjunction with the
defaultOpenprop to create an initially open preview card.- Type
string | null | undefined
handlePreviewCard.Handle<Payload>—
- Name
- Description
A handle to associate the preview card with a trigger. If specified, allows external triggers to control the card’s open state. Can be created with the PreviewCard.createHandle() method.
- Type
PreviewCard.Handle<Payload> | undefined
onOpenChangeCompletefunction—
- Description
Event handler called after any animations complete when the preview card is opened or closed.
- Type
((open: boolean) => void) | undefined
triggerIdstring | null—
- Name
- Description
ID of the trigger that the preview card is associated with. This is useful in conjunction with the
openprop to create a controlled preview card. There’s no need to specify this prop when the preview card is uncontrolled (that is, when theopenprop is not set).- Type
string | null | undefined
children| React.ReactNode
| PayloadChildRenderFunction<Payload>—
| PayloadChildRenderFunction<Payload>
- Name
- Description
The content of the preview card. This can be a regular React node or a render function that receives the
payloadof the active trigger.- Type
React.ReactNode | ((arg: { payload: unknown | undefined }) => ReactNode)<Payload> | undefined
PreviewCard.Root.StateHide
type PreviewCardRootState = {}PreviewCard.Root.ActionsHide
type PreviewCardRootActions = { unmount: () => void; close: () => void }PreviewCard.Root.ChangeEventReasonHide
type PreviewCardRootChangeEventReason =
| 'trigger-hover'
| 'trigger-focus'
| 'trigger-press'
| 'outside-press'
| 'escape-key'
| 'imperative-action'
| 'none'PreviewCard.Root.ChangeEventDetailsHide
type PreviewCardRootChangeEventDetails = (
| { reason: 'trigger-hover'; event: MouseEvent }
| { reason: 'trigger-focus'; event: FocusEvent }
| { reason: 'trigger-press'; event: MouseEvent | PointerEvent | TouchEvent | KeyboardEvent }
| { reason: 'outside-press'; event: MouseEvent | PointerEvent | TouchEvent }
| { reason: 'escape-key'; event: KeyboardEvent }
| { reason: 'imperative-action'; event: Event }
| { reason: 'none'; event: Event }
) & {
/** Cancels Base UI from handling the event. */
cancel: () => void;
/** Allows the event to propagate in cases where Base UI will stop the propagation. */
allowPropagation: () => void;
/** Indicates whether the event has been canceled. */
isCanceled: boolean;
/** Indicates whether the event is allowed to propagate. */
isPropagationAllowed: boolean;
/** The element that triggered the event, if applicable. */
trigger: Element | undefined;
preventUnmountOnClose: (() => void);
}Trigger
A link that opens the preview card.
Renders an <a> element.
handlePreviewCard.Handle<Payload>—
- Name
- Description
A handle to associate the trigger with a preview card.
- Type
PreviewCard.Handle<Payload> | undefined
payloadPayload—
- Name
- Description
A payload to pass to the preview card when it is opened.
- Type
Payload | undefined
delaynumber600
- Name
- Description
How long to wait before the preview card opens. Specified in milliseconds.
- Type
number | undefined- Default
600
closeDelaynumber300
- Name
- Description
How long to wait before closing the preview card. Specified in milliseconds.
- Type
number | undefined- Default
300
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | (( state: PreviewCard.Trigger.State, ) => string | undefined) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: PreviewCard.Trigger.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: PreviewCard.Trigger.State, ) => ReactElement) | undefined
data-popup-open
Present when the corresponding preview card is open.
| Attribute | Description | |
|---|---|---|
data-popup-open | Present when the corresponding preview card is open. | |
PreviewCard.Trigger.StateHide
type PreviewCardTriggerState = {
/** Whether the preview card is currently open. */
open: boolean;
}Portal
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.
containerUnion—
- Name
- Description
A parent element to render the portal element into.
- Type
| HTMLElement | ShadowRoot | React.RefObject<HTMLElement | ShadowRoot | null> | null | undefined
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | (( state: PreviewCard.Portal.State, ) => string | undefined) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: PreviewCard.Portal.State, ) => React.CSSProperties | undefined) | undefined
keepMountedbooleanfalse
- Name
- Description
Whether to keep the portal mounted in the DOM while the popup is hidden.
- Type
boolean | undefined- Default
false
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: PreviewCard.Portal.State, ) => ReactElement) | undefined
PreviewCard.Portal.StateHide
type PreviewCardPortalState = {}Backdrop
An overlay displayed beneath the popup.
Renders a <div> element.
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | (( state: PreviewCard.Backdrop.State, ) => string | undefined) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: PreviewCard.Backdrop.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: PreviewCard.Backdrop.State, ) => ReactElement) | undefined
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 is animating in.
data-ending-style
Present when the preview card is animating out.
| 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 is animating in. | |
data-ending-style | Present when the preview card is animating out. | |
PreviewCard.Backdrop.StateHide
type PreviewCardBackdropState = {
/** Whether the preview card is currently open. */
open: boolean;
/** The transition status of the component. */
transitionStatus: TransitionStatus;
}Positioner
Positions the popup against the trigger.
Renders a <div> element.
disableAnchorTrackingbooleanfalse
- Description
Whether to disable the popup from tracking any layout shift of its positioning anchor.
- Type
boolean | undefined- Default
false
alignAlign'center'
- Name
- Description
How to align the popup relative to the specified side.
- Type
'start' | 'center' | 'end' | undefined- Default
'center'
alignOffsetnumber | OffsetFunction0
- Name
- Description
Additional offset along the alignment axis in pixels. Also accepts a function that returns the offset to read the dimensions of the anchor and positioner elements, along with its side and alignment.
The function takes a
dataobject parameter with the following properties:data.anchor: the dimensions of the anchor element with propertieswidthandheight.data.positioner: the dimensions of the positioner element with propertieswidthandheight.data.side: which side of the anchor element the positioner is aligned against.data.align: how the positioner is aligned relative to the specified side.
- Type
| number | ((data: { side: | 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'; align: 'start' | 'center' | 'end'; anchor: { width: number; height: number }; positioner: { width: number; height: number }; }) => number) | undefined- Default
0- Example
<Positioner alignOffset={({ side, align, anchor, positioner }) => { return side === 'top' || side === 'bottom' ? anchor.width : anchor.height; }} />
sideSide'bottom'
- Name
- Description
Which side of the anchor element to align the popup against. May automatically change to avoid collisions.
- Type
| 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start' | undefined- Default
'bottom'
sideOffsetnumber | OffsetFunction0
- Name
- Description
Distance between the anchor and the popup in pixels. Also accepts a function that returns the distance to read the dimensions of the anchor and positioner elements, along with its side and alignment.
The function takes a
dataobject parameter with the following properties:data.anchor: the dimensions of the anchor element with propertieswidthandheight.data.positioner: the dimensions of the positioner element with propertieswidthandheight.data.side: which side of the anchor element the positioner is aligned against.data.align: how the positioner is aligned relative to the specified side.
- Type
| number | ((data: { side: | 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'; align: 'start' | 'center' | 'end'; anchor: { width: number; height: number }; positioner: { width: number; height: number }; }) => number) | undefined- Default
0- Example
<Positioner sideOffset={({ side, align, anchor, positioner }) => { return side === 'top' || side === 'bottom' ? anchor.height : anchor.width; }} />
arrowPaddingnumber5
- Name
- Description
Minimum distance to maintain between the arrow and the edges of the popup.
Use it to prevent the arrow element from hanging out of the rounded corners of a popup.
- Type
number | undefined- Default
5
anchorUnion—
- Name
- Description
An element to position the popup against. By default, the popup will be positioned against the trigger.
- Type
| Element | VirtualElement | React.RefObject<Element | null> | (() => Element | VirtualElement | null) | null | undefined
collisionAvoidanceCollisionAvoidance—
- Description
Determines how to handle collisions when positioning the popup.
sidecontrols overflow on the preferred placement axis (top/bottomorleft/right):'flip': keep the requested side when it fits; otherwise try the opposite side (topandbottom, orleftandright).'shift': never change side; keep the requested side and move the popup within the clipping boundary so it stays visible.'none': do not correct side-axis overflow.
aligncontrols overflow on the alignment axis (start/center/end):'flip': keep side, but swapstartandendwhen the requested alignment overflows.'shift': keep side and requested alignment, then nudge the popup along the alignment axis to fit.'none': do not correct alignment-axis overflow.
fallbackAxisSidecontrols fallback behavior on the perpendicular axis when the preferred axis cannot fit:'start': allow perpendicular fallback and try the logical start side first (topbeforebottom, orleftbeforerightin LTR).'end': allow perpendicular fallback and try the logical end side first (bottombeforetop, orrightbeforeleftin LTR).'none': do not fallback to the perpendicular axis.
When
sideis'shift', explicitly settingalignonly supports'shift'or'none'. Ifalignis omitted, it defaults to'flip'.- Type
CollisionAvoidance | undefined- Example
<Positioner collisionAvoidance={{ side: 'shift', align: 'shift', fallbackAxisSide: 'none', }} />
collisionBoundaryBoundary'clipping-ancestors'
- Description
An element or a rectangle that delimits the area that the popup is confined to.
- Type
Boundary | undefined- Default
'clipping-ancestors'
collisionPaddingPadding5
- Name
- Description
Additional space to maintain from the edge of the collision boundary.
- Type
Padding | undefined- Default
5
stickybooleanfalse
- Name
- Description
Whether to maintain the popup in the viewport after the anchor element was scrolled out of view.
- Type
boolean | undefined- Default
false
positionMethod'absolute' | 'fixed''absolute'
- Name
- Description
Determines which CSS
positionproperty to use.- Type
'absolute' | 'fixed' | undefined- Default
'absolute'
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | (( state: PreviewCard.Positioner.State, ) => string | undefined) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: PreviewCard.Positioner.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: PreviewCard.Positioner.State, ) => ReactElement) | undefined
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-align
Indicates how the popup is aligned relative to specified side.
data-side
Indicates which side the popup is positioned relative to the trigger.
| 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-align | Indicates how the popup is aligned relative to specified side. | |
data-side | Indicates which side the popup is positioned relative to the trigger. | |
--anchor-height
The anchor’s height.
--anchor-width
The anchor’s width.
--available-height
The available height between the trigger and the edge of the viewport.
--available-width
The available width between the trigger and the edge of the viewport.
--transform-origin
The coordinates that this element is anchored to. Used for animations and transitions.
| CSS Variable | Description | |
|---|---|---|
--anchor-height | The anchor’s height. | |
--anchor-width | The anchor’s width. | |
--available-height | The available height between the trigger and the edge of the viewport. | |
--available-width | The available width between the trigger and the edge of the viewport. | |
--transform-origin | The coordinates that this element is anchored to. Used for animations and transitions. | |
PreviewCard.Positioner.PropsHide
Re-Export of Positioner props as PreviewCardPositionerProps
PreviewCard.Positioner.StateHide
type PreviewCardPositionerState = {
/** Whether the preview card is currently open. */
open: boolean;
/** The side of the anchor the component is placed on. */
side: 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start';
/** The alignment of the component relative to the anchor. */
align: 'start' | 'center' | 'end';
/** Whether the anchor element is hidden. */
anchorHidden: boolean;
/** Whether transitions should be skipped. */
instant: 'dismiss' | 'focus' | undefined;
}Popup
A container for the preview card contents.
Renders a <div> element.
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: PreviewCard.Popup.State) => string | undefined) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: PreviewCard.Popup.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: PreviewCard.Popup.State, ) => ReactElement) | undefined
data-open
Present when the preview card is open.
data-closed
Present when the preview card is closed.
data-align
Indicates how the popup is aligned relative to specified side.
data-side
Indicates which side the popup is positioned relative to the trigger.
data-starting-style
Present when the preview card is animating in.
data-ending-style
Present when the preview card is animating out.
| Attribute | Description | |
|---|---|---|
data-open | Present when the preview card is open. | |
data-closed | Present when the preview card is closed. | |
data-align | Indicates how the popup is aligned relative to specified side. | |
data-side | Indicates which side the popup is positioned relative to the trigger. | |
data-starting-style | Present when the preview card is animating in. | |
data-ending-style | Present when the preview card is animating out. | |
PreviewCard.Popup.StateHide
type PreviewCardPopupState = {
/** Whether the preview card is currently open. */
open: boolean;
/** The side of the anchor the component is placed on. */
side: 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start';
/** The alignment of the component relative to the anchor. */
align: 'start' | 'center' | 'end';
/** Whether transitions should be skipped. */
instant: 'dismiss' | 'focus' | undefined;
/** The transition status of the component. */
transitionStatus: TransitionStatus;
}Viewport
A viewport for displaying content transitions.
This component is only required if one popup can be opened by multiple triggers, its content change based on the trigger
and switching between them is animated.
Renders a <div> element.
childrenReact.ReactNode—
- Name
- Description
The content to render inside the transition container.
- Type
React.ReactNode | undefined
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | (( state: PreviewCard.Viewport.State, ) => string | undefined) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: PreviewCard.Viewport.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: PreviewCard.Viewport.State, ) => ReactElement) | undefined
data-activation-direction
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-current
Applied to the direct child of the viewport when no transitions are present or the new content when it’s entering.
data-instant
Present if animations should be instant.
data-previous
Applied to the direct child of the viewport that contains the exiting content when transitions are present.
data-transitioning
Indicates that the viewport is currently transitioning between old and new content.
| Attribute | Description | |
|---|---|---|
data-activation-direction | 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-current | Applied to the direct child of the viewport when no transitions are present or the new content when it’s entering. | |
data-instant | Present if animations should be instant. | |
data-previous | Applied to the direct child of the viewport that contains the exiting content when transitions are present. | |
data-transitioning | Indicates that the viewport is currently transitioning between old and new 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.
--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.
| CSS Variable | Description | |
|---|---|---|
--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. | |
--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. | |
PreviewCard.Viewport.StateHide
type PreviewCardViewportState = {
/** The activation direction of the transitioned content. */
activationDirection: string | undefined;
/** Whether the viewport is currently transitioning between contents. */
transitioning: boolean;
/** Present if animations should be instant. */
instant: 'dismiss' | 'focus' | undefined;
}Arrow
Displays an element positioned against the preview card anchor.
Renders a <div> element.
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: PreviewCard.Arrow.State) => string | undefined) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: PreviewCard.Arrow.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: PreviewCard.Arrow.State, ) => ReactElement) | undefined
data-open
Present when the preview card is open.
data-closed
Present when the preview card is closed.
data-uncentered
Present when the preview card arrow is uncentered.
data-align
Indicates how the popup is aligned relative to specified side.
data-side
Indicates which side the popup is positioned relative to the trigger.
| Attribute | Description | |
|---|---|---|
data-open | Present when the preview card is open. | |
data-closed | Present when the preview card is closed. | |
data-uncentered | Present when the preview card arrow is uncentered. | |
data-align | Indicates how the popup is aligned relative to specified side. | |
data-side | Indicates which side the popup is positioned relative to the trigger. | |
PreviewCard.Arrow.StateHide
type PreviewCardArrowState = {
/** Whether the preview card is currently open. */
open: boolean;
/** The side of the anchor the component is placed on. */
side: 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start';
/** The alignment of the component relative to the anchor. */
align: 'start' | 'center' | 'end';
/** Whether the arrow cannot be centered on the anchor. */
uncentered: boolean;
}createHandle
Creates a new handle to connect a PreviewCard.Root with detached PreviewCard.Trigger components.
Return value
PreviewCard.Handle<Payload>Handle
A handle to control a preview card imperatively and to associate detached triggers with it.
Properties
isOpenboolean
readonly
boolean- Name
- Description
Indicates whether the preview card is currently open.
- Type
boolean- Modifiers
readonly
Methods
open(triggerId)void
void- Name
- Description
Opens the preview card and associates it with the trigger with the given ID. The trigger must be a PreviewCard.Trigger component with this handle passed as a prop.
This method should only be called in an event handler or an effect (not during rendering).
- Parameters
triggerId—stringID of the trigger to associate with the preview card.
- Returns
void
close()void
void- Name
- Description
Closes the preview card.
- Returns
void