# Tooltip

> A short label shown on hover and keyboard focus, dismissed with Escape.

Use a tooltip to name an icon-only control or add a short hint, such as a keyboard shortcut. Never put essential information or interactive content in a tooltip: touch users can't hover.

```tsx
import { IconButton, Tooltip } from "@aloxe/react";
import { Copy } from "lucide-react";

export default function TooltipBasic() {
  return (
    <Tooltip content="Copy link">
      <IconButton variant="secondary" aria-label="Copy link">
        <Copy />
      </IconButton>
    </Tooltip>
  );
}
```

## Installation

```bash
npm i @aloxe/react @aloxe/tokens
```

Then add the CSS imports from [Installation](/docs/getting-started/installation).

## Usage

```tsx
import { IconButton, Tooltip } from "@aloxe/react";
import { Copy } from "lucide-react";

<Tooltip content="Copy link">
  <IconButton aria-label="Copy link">
    <Copy />
  </IconButton>
</Tooltip>
```

The child is the trigger: one focusable element that has its own accessible name. The tooltip repeats that name for people who can see it; it doesn't replace it.

The tooltip opens in a popup attached to the page body. It copies the `data-theme` and `data-brand` of its trigger's surroundings.

## Examples

### Placements

`placement` sets the preferred side. The tooltip flips to the other side when there isn't room.

```tsx
import { Button, Tooltip } from "@aloxe/react";

const placements = ["top", "right", "bottom", "left"] as const;

export default function TooltipPlacements() {
  return (
    <div className="flex flex-wrap items-center justify-center gap-3">
      {placements.map((placement) => (
        <Tooltip key={placement} content={`Shown on the ${placement}`} placement={placement}>
          <Button variant="secondary" size="sm">
            {placement.charAt(0).toUpperCase() + placement.slice(1)}
          </Button>
        </Tooltip>
      ))}
    </div>
  );
}
```

### Hint

A tooltip can add a hint, such as a shortcut, to a button that already has a visible label.

```tsx
import { Button, Tooltip } from "@aloxe/react";

export default function TooltipHint() {
  return (
    <Tooltip content="Ctrl S" placement="bottom">
      <Button>Save</Button>
    </Tooltip>
  );
}
```

## Accessibility

| Key | Action |
| --- | --- |
| Tab | Moving focus to the trigger opens the tooltip right away. |
| Escape | Closes the tooltip; focus stays on the trigger. |

- Hovering opens it after 400 ms. Moving the pointer onto the tooltip keeps it open.
- The tooltip has `role="tooltip"`. It isn't linked to the trigger with `aria-describedby`, so the trigger must carry its own name.
- Text is Label Sm on the inverse surface, above 4.5:1 in both themes.

## API reference

Every part accepts `className` and renders a `data-aloxe` attribute you can target in CSS, such as `[data-aloxe="tooltip"]`.

**Tooltip** (extends Base UI Tooltip)

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `content` | `ReactNode` |  | Yes | A short label or hint. No links or buttons inside. |
| `children` | `ReactElement` |  | Yes | One focusable trigger that has its own accessible name, e.g. an IconButton. |
| `placement` | `"top" \| "bottom" \| "left" \| "right"` | `"top"` |  | Preferred side. Flips to the opposite side when there is no room. |
| `delay` | `number` | `400` |  | Hover delay in ms before opening. Keyboard focus opens it immediately. |
| `closeDelay` | `number` | `0` |  | Delay in ms before closing once the pointer leaves. |
| `open` | `boolean` |  |  | Controlled open state. Pair with onOpenChange. |
| `defaultOpen` | `boolean` | `false` |  | Initial open state when uncontrolled. |
| `onOpenChange` | `(open: boolean, details) => void` |  |  | Called when the tooltip opens or closes. |
| `disabled` | `boolean` | `false` |  | Never shows the tooltip; the trigger keeps working. |
| `className` | `string` |  |  | Classes for the tooltip bubble. |

## Figma

Matches the **Tooltip** component. Figma `Placement` (`Top`, `Bottom`, `Left`, `Right`) maps to `placement` and `Text` to `content`.

See [Figma](/docs/getting-started/figma) for where to get the file and how its names map to code.
