# Tooltip URL: https://ark-ui.com/docs/components/tooltip Source: https://raw.githubusercontent.com/chakra-ui/ark/refs/heads/main/website/src/content/pages/components/tooltip.mdx A label that provides information on hover or focus. --- ## Anatomy ```tsx ``` ## Examples **Example: basic** ```ripple import { Tooltip } from 'ark-ripple/tooltip'; import { Portal } from 'ark-ripple/portal'; import styles from 'styles/tooltip.module.css'; export component Basic() { {'Hover Me'} {'I am a tooltip!'} } ``` ### Controlled To create a controlled Tooltip component, manage the state of whether the tooltip is open using the `open` prop: **Example: controlled** ```ripple import { Tooltip } from 'ark-ripple/tooltip'; import { Portal } from 'ark-ripple/portal'; import { track } from 'ripple'; import styles from 'styles/tooltip.module.css'; import button from 'styles/button.module.css'; export component Controlled() { let open = track(false);
{ @open = e.open; }} > {'Hover Me'} {'I am a tooltip!'}
} ``` ### Root Provider An alternative way to control the tooltip is to use the `RootProvider` component and the `useTooltip` hook. This way you can access the state and methods from outside the component. **Example: root-provider** ```ripple import { Tooltip, useTooltip } from 'ark-ripple/tooltip'; import { Portal } from 'ark-ripple/portal'; import styles from 'styles/tooltip.module.css'; export component RootProvider() { const tooltip = useTooltip(); {'Open: '} {String(@tooltip.open)} {'Hover Me'} {'I am a tooltip!'} } ``` ### Arrow To display an arrow pointing to the trigger from the tooltip, use the `Tooltip.Arrow` and `Tooltip.ArrowTip` components: **Example: arrow** ```ripple import { Tooltip } from 'ark-ripple/tooltip'; import { Portal } from 'ark-ripple/portal'; import styles from 'styles/tooltip.module.css'; export component Arrow() { {'Hover Me'} {'I am a tooltip!'} } ``` ### Delay To configure the open and close delay for the Tooltip, use the `closeDelay` and `openDelay` props: **Example: delay** ```ripple import { Tooltip } from 'ark-ripple/tooltip'; import { Portal } from 'ark-ripple/portal'; import styles from 'styles/tooltip.module.css'; export component Delay() { {'Hover Me'} {'I am a tooltip!'} } ``` ### Positioning To customize the position of the Tooltip relative to the trigger, use the `positioning` prop: **Example: positioning** ```ripple import { Tooltip } from 'ark-ripple/tooltip'; import { Portal } from 'ark-ripple/portal'; import styles from 'styles/tooltip.module.css'; export component Positioning() { {'Hover Me'} {'I am a tooltip!'} } ``` ### Context Access the tooltip's state and methods with `Tooltip.Context` or the `useTooltipContext` hook: **Example: context** ```ripple import { Tooltip } from 'ark-ripple/tooltip'; import { Portal } from 'ark-ripple/portal'; import styles from 'styles/tooltip.module.css'; export component Context() { {'Hover Me'} component children({ context }) { {'This tooltip is open: '} {String(@context.open)} } } ``` ### Within Fixed Containers When rendering a tooltip inside a fixed-position container, set `positioning.strategy` to `"fixed"` to ensure proper positioning. **Example: within-fixed** ```ripple import { Tooltip } from 'ark-ripple/tooltip'; import { Portal } from 'ark-ripple/portal'; import styles from 'styles/tooltip.module.css'; export component WithinFixed() {
{'Hover Me'} {'I am a tooltip!'}
} ``` ## API Reference ### Props **Component API Reference** **Root Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `aria-label` | `string` | No | Custom label for the tooltip. | | `closeDelay` | `number` | No | The close delay of the tooltip. | | `closeOnClick` | `boolean` | No | Whether the tooltip should close on click | | `closeOnEscape` | `boolean` | No | Whether to close the tooltip when the Escape key is pressed. | | `closeOnPointerDown` | `boolean` | No | Whether to close the tooltip on pointerdown. | | `closeOnScroll` | `boolean` | No | Whether the tooltip should close on scroll | | `defaultOpen` | `boolean` | No | The initial open state of the tooltip when rendered. Use when you don't need to control the open state of the tooltip. | | `disabled` | `boolean` | No | Whether the tooltip is disabled | | `id` | `string` | No | The unique identifier of the machine. | | `ids` | `Partial<{ trigger: string; content: string; arrow: string; positioner: string }>` | No | The ids of the elements in the tooltip. Useful for composition. | | `immediate` | `boolean` | No | Whether to synchronize the present change immediately or defer it to the next frame | | `interactive` | `boolean` | No | Whether the tooltip's content is interactive. In this mode, the tooltip will remain open when user hovers over the content. | | `lazyMount` | `boolean` | No | Whether to enable lazy mounting | | `onExitComplete` | `VoidFunction` | No | Function called when the animation ends in the closed state | | `onOpenChange` | `(details: OpenChangeDetails) => void` | No | Function called when the tooltip is opened. | | `open` | `boolean` | No | The controlled open state of the tooltip | | `openDelay` | `number` | No | The open delay of the tooltip. | | `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]` | tooltip | | `[data-part]` | content | | `[data-state]` | "open" | "closed" | | `[data-instant]` | | | `[data-placement]` | The placement of the content | **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` | `UseTooltipReturn` | 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]` | tooltip | | `[data-part]` | trigger | | `[data-expanded]` | Present when expanded | | `[data-state]` | "open" | "closed" | ### Context **API:** | Property | Type | Description | |----------|------|-------------| | `open` | `boolean` | Whether the tooltip is open. | | `setOpen` | `(open: boolean) => void` | Function to open the tooltip. | | `reposition` | `(options?: Partial) => void` | Function to reposition the popover | ## Accessibility Complies with the [Tooltip WAI-ARIA design pattern](https://www.w3.org/WAI/ARIA/apg/patterns/tooltip/). ### Keyboard Support