# Hover Card URL: https://ark-ui.com/docs/components/hover-card Source: https://raw.githubusercontent.com/chakra-ui/ark/refs/heads/main/website/src/content/pages/components/hover-card.mdx A card that appears when a user hovers over an element. --- ## Anatomy ```tsx ``` ## Examples **Example: basic** ```ripple import { HoverCard } from 'ark-ripple/hover-card'; import { Portal } from 'ark-ripple/portal'; import styles from 'styles/hover-card.module.css'; export component Basic() {

{'Liked by '} component asChild({ propsFn }) { {'@sarah_chen'} } {' and 3 others'}

Sarah Chen

{'Sarah Chen'}

{'@sarah_chen'}

{'Design Engineer at Acme Inc. Building beautiful interfaces and design systems.'}

{'2,456'} {'Following'}
{'14.5K'} {'Followers'}
} ``` ### Controlled The controlled `HoverCard` component provides an interface for managing the state of the hover card using the `open` and `onOpenChange` props: **Example: controlled** ```ripple import { HoverCard } from 'ark-ripple/hover-card'; import { Portal } from 'ark-ripple/portal'; import { track } from 'ripple'; import button from 'styles/button.module.css'; import styles from 'styles/hover-card.module.css'; export component Controlled() { let open = track(false);
{ @open = e.open; }} >

{'Liked by '} component asChild({ propsFn }) { {'@sarah_chen'} } {' and 3 others'}

Sarah Chen

{'Sarah Chen'}

{'@sarah_chen'}

{'Design Engineer at Acme Inc.'}

} ``` ### Root Provider An alternative way to control the hover card is to use the `RootProvider` component and the `useHoverCard` hook. This way you can access the state and methods from outside the component. **Example: root-provider** ```ripple import { HoverCard, useHoverCard } from 'ark-ripple/hover-card'; import { Portal } from 'ark-ripple/portal'; import styles from 'styles/hover-card.module.css'; export component RootProvider() { const hoverCard = useHoverCard();
{'Open: '} {String(@hoverCard.open)}

{'Liked by '} component asChild({ propsFn }) { {'@sarah_chen'} } {' and 3 others'}

Sarah Chen

{'Sarah Chen'}

{'@sarah_chen'}

{'Design Engineer at Acme Inc.'}

} ``` ### Delay Control the open and close delay of the hover card using the `openDelay` and `closeDelay` props: **Example: delay** ```ripple import { HoverCard } from 'ark-ripple/hover-card'; import { Portal } from 'ark-ripple/portal'; import styles from 'styles/hover-card.module.css'; export component Delay() {

{'Liked by '} component asChild({ propsFn }) { {'@sarah_chen'} } {' and 3 others'}

Sarah Chen

{'Sarah Chen'}

{'@sarah_chen'}

{'Design Engineer at Acme Inc.'}

} ``` ### Positioning The `HoverCard` component can be customized in its placement and distance from the trigger element through the `positioning` prop: **Example: positioning** ```ripple import { HoverCard } from 'ark-ripple/hover-card'; import { Portal } from 'ark-ripple/portal'; import styles from 'styles/hover-card.module.css'; export component Positioning() {

{'Liked by '} component asChild({ propsFn }) { {'@sarah_chen'} } {' and 3 others'}

Sarah Chen

{'Sarah Chen'}

{'@sarah_chen'}

{'Design Engineer at Acme Inc.'}

} ``` ### Context Access the hover card's state with `HoverCard.Context` or the `useHoverCardContext` hook: **Example: context** ```ripple import { HoverCard } from 'ark-ripple/hover-card'; import { Portal } from 'ark-ripple/portal'; import { ChevronDown, ChevronUp } from 'lucide-ripple'; import styles from 'styles/hover-card.module.css'; export component Context() { const s = 'www';

{'Liked by '} component asChild({ propsFn }) { {'@sarah_chen '} component children({ context }) { {s} if (@context.open) { } else { } } } {' and 3 others'}

Sarah Chen

{'Sarah Chen'}

{'@sarah_chen'}

{'Design Engineer at Acme Inc.'}

} ``` ## API Reference ### Props **Component API Reference** **Root Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `closeDelay` | `number` | No | The duration from when the mouse leaves the trigger or content until the hover card closes. | | `defaultOpen` | `boolean` | No | The initial open state of the hover card when rendered. Use when you don't need to control the open state of the hover card. | | `disabled` | `boolean` | No | Whether the hover card is disabled | | `id` | `string` | No | The unique identifier of the machine. | | `ids` | `Partial<{ trigger: string; content: string; positioner: string; arrow: string }>` | No | The ids of the elements in the popover. Useful for composition. | | `immediate` | `boolean` | No | Whether to synchronize the present change immediately or defer it to the next frame | | `lazyMount` | `boolean` | No | Whether to enable lazy mounting | | `onExitComplete` | `VoidFunction` | No | Function called when the animation ends in the closed state | | `onFocusOutside` | `(event: FocusOutsideEvent) => void` | No | Function called when the focus is moved outside the component | | `onInteractOutside` | `(event: InteractOutsideEvent) => void` | No | Function called when an interaction happens outside the component | | `onOpenChange` | `(details: OpenChangeDetails) => void` | No | Function called when the hover card opens or closes. | | `onPointerDownOutside` | `(event: PointerDownOutsideEvent) => void` | No | Function called when the pointer is pressed down outside the component | | `open` | `boolean` | No | The controlled open state of the hover card | | `openDelay` | `number` | No | The duration from when the mouse enters the trigger until the hover card opens. | | `positioning` | `PositioningOptions` | No | The user provided options used to position the popover content | | `present` | `boolean` | No | Whether the node is present (controlled by the user) | | `skipAnimationOnMount` | `boolean` | No | Whether to allow the initial presence animation. | | `unmountOnExit` | `boolean` | No | Whether to unmount on exit. | **Arrow Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. | **Arrow CSS Variables:** | Variable | Description | |----------|-------------| | `--arrow-size` | The size of the arrow | | `--arrow-size-half` | Half the size of the arrow | | `--arrow-background` | Use this variable to style the arrow background | | `--arrow-offset` | The offset position of the arrow | **ArrowTip Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. | **Content Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. | **Content Data Attributes:** | Attribute | Value | |-----------|-------| | `[data-scope]` | hover-card | | `[data-part]` | content | | `[data-state]` | "open" | "closed" | | `[data-nested]` | popover | | `[data-has-nested]` | popover | | `[data-placement]` | The placement of the content | **Content CSS Variables:** | Variable | Description | |----------|-------------| | `--layer-index` | The index of the dismissable in the layer stack | | `--nested-layer-count` | The number of nested hover-cards | **Positioner Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. | **Positioner CSS Variables:** | Variable | Description | |----------|-------------| | `--reference-width` | The width of the reference element | | `--reference-height` | The height of the root | | `--available-width` | The available width in viewport | | `--available-height` | The available height in viewport | | `--x` | The x position for transform | | `--y` | The y position for transform | | `--z-index` | The z-index value | | `--transform-origin` | The transform origin for animations | **RootProvider Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `value` | `UseHoverCardReturn` | Yes | | | `immediate` | `boolean` | No | Whether to synchronize the present change immediately or defer it to the next frame | | `lazyMount` | `boolean` | No | Whether to enable lazy mounting | | `onExitComplete` | `VoidFunction` | No | Function called when the animation ends in the closed state | | `present` | `boolean` | No | Whether the node is present (controlled by the user) | | `skipAnimationOnMount` | `boolean` | No | Whether to allow the initial presence animation. | | `unmountOnExit` | `boolean` | No | Whether to unmount on exit. | **Trigger Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. | **Trigger Data Attributes:** | Attribute | Value | |-----------|-------| | `[data-scope]` | hover-card | | `[data-part]` | trigger | | `[data-placement]` | The placement of the trigger | | `[data-state]` | "open" | "closed" | ### Context **API:** | Property | Type | Description | |----------|------|-------------| | `open` | `boolean` | Whether the hover card is open | | `setOpen` | `(open: boolean) => void` | Function to open the hover card | | `reposition` | `(options?: Partial) => void` | Function to reposition the popover |