# 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.

---

<ComponentPreview id="Tooltip" />

## Anatomy

<Anatomy id="tooltip" />

```tsx
<Tooltip.Root>
  <Tooltip.Trigger />
  <Tooltip.Positioner>
    <Tooltip.Arrow>
      <Tooltip.ArrowTip />
    </Tooltip.Arrow>
    <Tooltip.Content />
  </Tooltip.Positioner>
</Tooltip.Root>
```

## 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() {
  <Tooltip.Root>
    <Tooltip.Trigger class={styles.Trigger}>{'Hover Me'}</Tooltip.Trigger>
    <Portal>
      <Tooltip.Positioner>
        <Tooltip.Content class={styles.Content}>{'I am a tooltip!'}</Tooltip.Content>
      </Tooltip.Positioner>
    </Portal>
  </Tooltip.Root>
}

```

### 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);

  <div class="stack">
    <button
      type="button"
      onClick={() => {
        @open = !@open;
      }}
      class={button.Root}
    >
      {'Toggle'}
    </button>
    <Tooltip.Root
      {open}
      onOpenChange={(e) => {
        @open = e.open;
      }}
    >
      <Tooltip.Trigger class={styles.Trigger}>{'Hover Me'}</Tooltip.Trigger>
      <Portal>
        <Tooltip.Positioner>
          <Tooltip.Content class={styles.Content}>{'I am a tooltip!'}</Tooltip.Content>
        </Tooltip.Positioner>
      </Portal>
    </Tooltip.Root>
  </div>
}

```

### 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();

  <output>
    {'Open: '}
    {String(@tooltip.open)}
  </output>
  <Tooltip.RootProvider value={tooltip}>
    <Tooltip.Trigger class={styles.Trigger}>{'Hover Me'}</Tooltip.Trigger>
    <Portal>
      <Tooltip.Positioner>
        <Tooltip.Content class={styles.Content}>{'I am a tooltip!'}</Tooltip.Content>
      </Tooltip.Positioner>
    </Portal>
  </Tooltip.RootProvider>
}

```

### 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() {
  <Tooltip.Root>
    <Tooltip.Trigger class={styles.Trigger}>{'Hover Me'}</Tooltip.Trigger>
    <Portal>
      <Tooltip.Positioner>
        <Tooltip.Content class={styles.Content}>
          <Tooltip.Arrow class={styles.Arrow}>
            <Tooltip.ArrowTip class={styles.ArrowTip} />
          </Tooltip.Arrow>
          {'I am a tooltip!'}
        </Tooltip.Content>
      </Tooltip.Positioner>
    </Portal>
  </Tooltip.Root>
}

```

### 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() {
  <Tooltip.Root closeDelay={0} openDelay={0}>
    <Tooltip.Trigger class={styles.Trigger}>{'Hover Me'}</Tooltip.Trigger>
    <Portal>
      <Tooltip.Positioner>
        <Tooltip.Content class={styles.Content}>{'I am a tooltip!'}</Tooltip.Content>
      </Tooltip.Positioner>
    </Portal>
  </Tooltip.Root>
}

```

### 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() {
  <Tooltip.Root
    positioning={{
      placement: 'left-start',
      offset: { mainAxis: 12, crossAxis: 12 },
    }}
  >
    <Tooltip.Trigger class={styles.Trigger}>{'Hover Me'}</Tooltip.Trigger>
    <Portal>
      <Tooltip.Positioner>
        <Tooltip.Content class={styles.Content}>{'I am a tooltip!'}</Tooltip.Content>
      </Tooltip.Positioner>
    </Portal>
  </Tooltip.Root>
}

```

### 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() {
  <Tooltip.Root>
    <Tooltip.Trigger class={styles.Trigger}>{'Hover Me'}</Tooltip.Trigger>
    <Portal>
      <Tooltip.Positioner>
        <Tooltip.Context>
          component children({ context }) {
            <Tooltip.Content class={styles.Content}>
              {'This tooltip is open: '}
              {String(@context.open)}
            </Tooltip.Content>
          }
        </Tooltip.Context>
      </Tooltip.Positioner>
    </Portal>
  </Tooltip.Root>
}

```

### 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() {
  <div style={{ position: 'fixed', top: '40px', left: '40px', padding: '40px', background: 'red' }}>
    <Tooltip.Root positioning={{ strategy: 'fixed' }}>
      <Tooltip.Trigger class={styles.Trigger}>{'Hover Me'}</Tooltip.Trigger>
      <Portal>
        <Tooltip.Positioner>
          <Tooltip.Content class={styles.Content}>{'I am a tooltip!'}</Tooltip.Content>
        </Tooltip.Positioner>
      </Portal>
    </Tooltip.Root>
  </div>
}

```

## 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<PositioningOptions>) => 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

<KeyBindingsTable id="tooltip" />