<!-- generated by scripts/gen-docs.mjs from docs/system/tooltip.md. Edit the source and rerun. -->
# Tooltip

## Description
Names a control that has no visible name, on hover and on keyboard focus, after one shared delay.

`import { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider } from "@/components/cobalt/ui/tooltip"`, source `registry/cobalt/ui/tooltip.tsx`, status `ready-with-gaps`.
Foundation: `shadcn tooltip (base-luma, base)`. Traps checked: `trap/tooltip-essential`, `trap/tooltip-disabled-trigger`, `trap/tooltip-interactive`, `trap/tooltip-group-delay`, `trap/overlay-title` (n/a: the tooltip is the name, not a surface with a title), `trap/overlay-focus-return` (n/a: a tooltip takes no focus), `trap/overlay-conditional-render`, `trap/exit-eats-input`, `trap/escape-nested`, `trap/open-trigger-unfocused`, `trap/touch-autofocus` (n/a: nothing focusable inside), `trap/motion-origin`, `trap/motion-exit-slower`, `trap/reduced-motion-ignored`, `trap/motion-frequent`.

### Foundation
| Given by the foundation | Added by the team |
|---|---|
| Base UI `Tooltip`: a portalled popup opened on hover and on focus after `delay`, closed on leave, blur and Escape, not focusable; a `Provider` that shares the delay across a group and opens a neighbour at once while one is showing (`data-instant`); a `Positioner`; the trigger keeps its own accessible name and the popup carries no role or `aria-describedby` | `TooltipProvider` defaults `delay` to `TOOLTIP_DELAY_MS`, 400ms, from `registry/cobalt/lib/motion.ts` (`registry/cobalt/ui/tooltip.tsx:24`); the popup rendered into the portal container from `registry/cobalt/lib/portal.tsx`; `side="top"`, `sideOffset={6}` (`TOOLTIP_OFFSET`, the same gap the chart's tooltip keeps from its mark) and `align="center"` as defaults; `collisionPadding={8}` (`TOOLTIP_EDGE`), the room every popup keeps from the screen's edges, so a tooltip near one shifts in to 8px instead of touching it (measured 8px and 8.2px from the left and right edges at 390 for SourceLine's date pinned against each, `.design-system/evidence/tooltip/edge-390.png`); the `--tip` fill with `--tip-foreground` text, dark in both themes (oklch 0.18 in light, 0.27 in dark, where every chart series swatch holds at least 3:1 on it: 3.09 to 5.72 in light, 3.11 to 7.96 in dark), 12px regular text, as every line of body text is, `rounded-md`, a 1px `--edge` ring as every floating surface carries, a 320px max width inside which a label with no space to wrap at, such as an address or a hash, breaks anywhere (`wrap-anywhere`) instead of running past the box, and no arrow: the label sits 6px from what it names, which already says what it belongs to, and an arrow only adds a shape to a 24px label; the surface classes are exported as `tooltipSurface`, which the chart's tooltip uses too; `popup-motion` on `--t-press` instead of `--t-pop`, so the name appears in 140ms |

## Examples
Tooltips naming icon-only controls, sharing one provider and its delay.

Real uses, 1 call site (`rg -n "<Tooltip\b" app registry --glob '!registry/cobalt/ui/*'`): `TipView` in `registry/cobalt/lib/truncated-text.tsx:369`, the system tooltip that `TruncatedText`, `LazyTip` and `TruncatedTextGroup` mount on intent instead of a Base UI trigger per label. A cut label, a flag's name or a tag row's "+N" stays a plain element (marked `data-tip`) until the pointer rests on it for the delay or the keyboard focuses it; only then does a Tooltip mount, anchored to it through `TooltipContent`'s `anchor`, and a label asks whether it is cut at that moment, so a label that fits opens nothing, in place of the browser's `title`. Inside a `TruncatedTextGroup` (`registry/cobalt/lib/truncated-text.tsx:411`) every label shares the group's one tooltip, found from the event with no listener per label, so a long table holds one tooltip and no trigger per cell (DataTable wraps its rows in one); a neighbour opens at once with `data-instant="delay"`, as the instant state says, where the shared Base UI root before faded it in again. The showcase chrome renders no Tooltip of its own and mounts no `TooltipProvider` (see the Rules), and the examples folder does not count.

Uses inside the registry, which other components build on (planned as product uses once the first screen lands on the system):
- The icon button, whose one `label` is the button's `aria-label` and its tooltip, `registry/cobalt/ui/icon-button.tsx:66-67`.
- The segmented control's icon-only options, each a labelled radio with its label as the tooltip, `registry/cobalt/ui/segmented-control.tsx:133-135`.
- The names a glyph or a short form stands for: a key symbol's name in Kbd, a flag's country in Flag, the full date of a RelativeTime and a MessageTime, the page of a Nav glyph below 768px, and the hidden tags behind TagRow's "+N".
- Through `TruncatedText`, the whole label of a cut Badge, Tag, Pill, Toggle, ChipRow chip, BackLink, NavTabs tab, ItemTitle, MediaTileTitle, FileDrop name and DataTable cell.

### Example files
| File | Covers | Caption |
|---|---|---|
| `docs/system/examples/tooltip/default.tsx` | default | Two icon buttons that share one provider and its delay |
| Not applicable: the open state is reached by hovering or focusing either button in default.tsx | state:open | The dark label 6px above the control, after 400ms |
| Not applicable: the instant state is reached by moving from one button to the next in default.tsx | state:instant | The neighbour's label appears at once with no transition |
| Not applicable: closing is reached by leaving or blurring the button | state:closing | The label fades back toward the control in 70 percent of the press time |
| `docs/system/examples/tooltip/in-icon-button.tsx` | composition:IconButton | IconButton uses one string for its name and its tooltip, beside a CopyButton under the same provider |
| Not applicable: the keys belong to IconButton's `shortcut`, shown in `docs/system/examples/icon-button/with-shortcut.tsx` | state:with-shortcut | The keys that do the same follow the name as quiet text, "Next paper J", through IconButton's `shortcut` |

Example: Two icon buttons that share one provider and its delay (`docs/system/examples/tooltip/default.tsx`)

```tsx
import { useState } from "react";

import { EyeIcon, EyeOffIcon } from "@/components/cobalt/icon";
import { Button } from "@/components/cobalt/ui/button";
import { CopyButton } from "@/components/cobalt/ui/copy-button";
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/cobalt/ui/tooltip";

const BALANCE = "€1,240.00";

export default function Example() {
  const [hidden, setHidden] = useState(false);
  const hideLabel = hidden ? "Show balance" : "Hide balance";
  return (
    <TooltipProvider>
      <div className="flex items-center gap-2">
        <span className="w-24 text-sm tabular-nums">{hidden ? "••••" : BALANCE}</span>
        <Tooltip>
          <TooltipTrigger
            render={<Button variant="ghost" size="icon" aria-label={hideLabel} />}
            onClick={() => setHidden(!hidden)}
          >
            {hidden ? <EyeOffIcon /> : <EyeIcon />}
          </TooltipTrigger>
          <TooltipContent>{hideLabel}</TooltipContent>
        </Tooltip>
        {/* The system's copy button carries its own tooltip, and shares this provider's delay. */}
        <CopyButton value={BALANCE} label="Copy balance" />
      </div>
    </TooltipProvider>
  );
}
```

Example: IconButton uses one string for its name and its tooltip, beside a CopyButton under the same provider (`docs/system/examples/tooltip/in-icon-button.tsx`)

```tsx
import { DownloadIcon } from "@/components/cobalt/icon";
import { CopyButton } from "@/components/cobalt/ui/copy-button";
import { IconButton } from "@/components/cobalt/ui/icon-button";
import { TooltipProvider } from "@/components/cobalt/ui/tooltip";

const LINK = "https://example.com/reports/q3-holdings";

const holdings: [string, number][] = [
  ["Northgate Treasury 2031", 4.2],
  ["Calder Global Equity", 3.1],
  ["Harbour Short Duration", 2.6],
];

// The file the button hands back, written here so the download is real.
function download() {
  const rows = holdings.map(([name, weight]) => `${name},${weight.toFixed(1)}%`);
  const url = URL.createObjectURL(new Blob([["holding,weight", ...rows].join("\n")], { type: "text/csv" }));
  const link = document.createElement("a");
  link.href = url;
  link.download = "q3-holdings.csv";
  link.click();
  URL.revokeObjectURL(url);
}

export default function Example() {
  return (
    <TooltipProvider>
      <div className="flex w-full max-w-md items-center justify-between gap-3">
        <span className="min-w-0 truncate text-sm font-medium">Q3 holdings report</span>
        <div className="flex shrink-0 items-center gap-1">
          <IconButton icon={<DownloadIcon />} label="Download as spreadsheet" onClick={download} />
          <CopyButton value={LINK} label="Copy link" />
        </div>
      </div>
    </TooltipProvider>
  );
}
```

## Variants
Not applicable: a tooltip has one form. `side` and `align` on `TooltipContent` are positioning, not variants; every example keeps the default, above the control.

## States
| State | Trigger | What the user can do | Shown by, besides color | Checked by |
|---|---|---|---|---|
| closed | render | hover or focus the trigger | nothing is in the tree but the trigger, which keeps its own name | test |
| open | hover for `delay` ms, or keyboard focus | read the name; move on | the label 6px from the control, `data-popup-open` on the trigger | a11y scan |
| instant | hover a neighbour while one tooltip in the provider is showing | the same | the label with `data-instant="delay"` and no transition (`trap/tooltip-group-delay`) | a11y scan |
| closing | leave, blur, Escape | hover again | `data-ending-style` on the popup | by hand |
| with-shortcut | an IconButton given `shortcut` | read the name and the keys that do the same | the keys 6px after the name, in `--tip-foreground` at 70 percent, in the reader's own modifiers, "Search ⌘K" on a Mac and "Search Ctrl+K" elsewhere; plain text, never a key cap, on the same surface | test |

### State precedence
- Open and instant: instant wins. The second label appears with no delay and no transition while the first is up.
- Open and closing: closing wins. Leaving the trigger starts the fade, and the label takes no pointer input at any time.
- Closed and instant: Not applicable: instant needs another tooltip in the same provider to be open.
- With-shortcut and instant: both show. The neighbour's name and keys appear together with no transition.

### Motion
| Trigger | Kind | Preset | Properties | Reduced motion |
|---|---|---|---|---|
| closed to open | announce | `popup-motion` with `--popup-duration` set to `--t-press`, 140ms on `--curve`, a fade in place beside the control (`trap/motion-origin`: nothing scales) | opacity 0 to 1 | the fade stays |
| open to closed | announce | `popup-motion`, 70 percent of `--t-press` (`trap/motion-exit-slower`) | opacity 1 to 0 | the fade only |
| neighbour while one is open | announce | `data-instant`, 0ms (`trap/motion-frequent`) | none | none |
| words change while open | announce | the body eases to the new words' width on `ease-settle` over `--t-settle`, measured by a ResizeObserver, while Base UI keeps it centred over its control; it opens at its width with no easing; the words swap through `TextSwap fit` (`registry/cobalt/ui/tooltip.tsx:32`) | width | the width lands at once |

## Props

<!-- Props generated from registry/cobalt/ui/tooltip.tsx with TypeScript by scripts/props-table.mjs -->
### Tooltip

No props of its own.

Also accepts from Base UI: `actionsRef`, `defaultOpen`, `defaultTriggerId`, `disableHoverablePopup`, `disabled`, `handle`, `onOpenChange`, `onOpenChangeComplete`, `open`, `trackCursorAxis`, `triggerId`.

### TooltipTrigger

No props of its own.

Also accepts every native `<button>` attribute; from Base UI: `closeDelay`, `closeOnClick`, `delay`, `disabled`, `handle`, `payload`, `render`.

### TooltipContent

No props of its own.

Also accepts every native `<div>` attribute; from Base UI: `align`, `alignOffset`, `anchor`, `collisionPadding`, `render`, `side`, `sideOffset`.

### TooltipProvider

No props of its own.

Also accepts from Base UI: `closeDelay`, `delay`, `timeout`.

`TooltipProvider` takes `delay` (default `TOOLTIP_DELAY_MS`, 400ms), `closeDelay` and `timeout`, and renders no element of its own. `TooltipContent` takes the positioner's `side` (default `top`), `sideOffset` (6, `TOOLTIP_OFFSET`), `align` (`center`), `alignOffset`, `collisionPadding` (8, `TOOLTIP_EDGE`) and `anchor`, for a tooltip with no trigger of its own, such as the one a data table shares across its cut cells, and every popup prop. Its body is always as wide as its words: it never holds a longer wording's width. Everything on Base UI's root passes through `Tooltip`: `open`, `defaultOpen`, `onOpenChange`, `disabled`, `disableHoverablePopup`, `trackCursorAxis`. `TooltipTrigger` takes `render` to compose with Button. `className` on `TooltipContent` is merged last and is for placement.

## Usage

### When to use
- A control is only an icon, and a pointer user needs its name without pressing it.
- A row of icon-only controls, such as a toolbar or the segmented control's icon options, needs names that appear as the hand moves along.
- An icon-only control also answers a key. Pass the keys to IconButton's `shortcut`, which writes them after the name; nothing else goes after it.

### When not to use
- The text is more than the control's name, such as a reason or a description. Use Popover instead, or visible text beside the control.
- The content holds a link or a button. Use Popover instead.
- The control is disabled and the text says why. Use visible text beside it instead, or keep the control focusable with `aria-disabled` and the reason in a Popover.

### Rules
- `rule/tooltip-under-one-provider`: When tooltips render in an app, mount one `TooltipProvider` at the app's root, instead of leaving each `Tooltip` on its own, because the provider sets the 400ms delay and lets a neighbour open at once while one is showing, and without it Base UI waits 600ms on every control (`trap/tooltip-group-delay`). Evidence: measured 409ms to open with the provider and 63ms for the neighbour, .design-system/evidence/tooltip/hover-1280.json; measured 613ms on the icon button page, where the showcase mounts no provider, .design-system/evidence/tooltip/icon-button-delay-1280.json. Check: review of `app/main.tsx` for one `TooltipProvider`; test `tooltip.test.tsx` renders the provider with no element of its own.
  - Don't: `<Tooltip><TooltipTrigger render={<IconButton icon={<CopyIcon />} label="Copy link" />} /><TooltipContent>Copy link</TooltipContent></Tooltip>`
  - Do: `<TooltipProvider><App /></TooltipProvider>`
- `rule/tooltip-text-only`: When the content would hold a link, a button or a field, use Popover instead of `TooltipContent`, because the tooltip closes when the pointer leaves the trigger and takes no focus, so nothing inside it can be reached (`trap/tooltip-interactive`). Evidence: app 2/2 registry uses render text only (`registry/cobalt/ui/icon-button.tsx:67`, `registry/cobalt/ui/segmented-control.tsx:135`); principle input: a hover surface cannot hold a target the pointer must leave the trigger to reach. Check: review of every `TooltipContent` for an element with a role.
  - Don't: `<TooltipContent>Shared with 3 people. <a href="/share">Manage</a></TooltipContent>`
  - Do: `<PopoverContent><PopoverTitle>Sharing</PopoverTitle><Button render={<a href="/share" />} variant="ghost">Manage</Button></PopoverContent>`
- `rule/tooltip-names-the-trigger`: When the trigger is icon-only, give the trigger `aria-label` equal to the tooltip's text, or render it through `IconButton`, because Base UI puts no role on the tooltip and no `aria-describedby` on the trigger, so the tooltip is visual only and the name must live on the control. Evidence: measured no `role` on the popup and no `aria-describedby` on the trigger, .design-system/evidence/tooltip/hover-1280.json; app 2/2 registry uses name the control itself (`registry/cobalt/ui/icon-button.tsx:53` through `aria-label`, `registry/cobalt/ui/segmented-control.tsx:111` through the radio's label); principle wcag: 4.1.2 Name, role, value. Check: test `tooltip.test.tsx` renders the trigger with its `aria-label`; review of every `TooltipTrigger`.
  - Don't: `<Tooltip><TooltipTrigger render={<Button size="icon" />}><BellIcon /></TooltipTrigger><TooltipContent>Notifications</TooltipContent></Tooltip>`
  - Do: `<IconButton icon={<BellIcon />} label="Notifications" />`
- `rule/tooltip-not-on-a-disabled-trigger`: When a control is disabled and needs a reason, show the reason as visible text beside it, or keep the control focusable with `aria-disabled` and put the reason in a Popover, instead of a `Tooltip` on a `disabled` button, because a disabled button takes no hover and no focus, so the tooltip cannot open (`trap/tooltip-disabled-trigger`). Evidence: principle platform: a `disabled` button fires no pointer or focus events; app 2/2 registry uses either open no tooltip while the control is disabled (`registry/cobalt/ui/icon-button.tsx:46`) or wrap a control that is never disabled (`registry/cobalt/ui/segmented-control.tsx:133`). Check: review of every `TooltipTrigger` whose rendered control passes `disabled`.
  - Don't: `<Tooltip><TooltipTrigger render={<Button disabled />}>Publish</TooltipTrigger><TooltipContent>Add a title first</TooltipContent></Tooltip>`
  - Do: `<Button aria-disabled>Publish</Button><p className="text-sm text-muted-foreground">Add a title first.</p>`
- `rule/tooltip-nothing-essential`: When text is needed to finish the task, such as a status or a count, show it in the page instead of only in `TooltipContent`, because the tooltip opens on hover and keyboard focus only, and touch has neither (`trap/tooltip-essential`). Evidence: measured the tooltip opening on hover and on focus and on nothing else, .design-system/evidence/tooltip/hover-1280.json; principle input: touch has no hover; app 2/2 registry uses repeat a name the control already carries. Check: review of every `TooltipContent` whose text is not the trigger's name.
  - Don't: `<Tooltip><TooltipTrigger render={<Badge />}>3</TooltipTrigger><TooltipContent>3 unread, 1 mentions you</TooltipContent></Tooltip>`
  - Do: `<Badge>3 unread</Badge>`

### Content
- Follows `rule/writing-tooltip-is-the-name`.
- `rule/tooltip-sentence-case`: When the tooltip text is written, use sentence case with no end punctuation, such as "Copy link", instead of "Copy Link" or "Copy link.", because the text is the control's name as a screen reader says it and as it shows at 12px, where a period reads as noise. Evidence: person D11; app 2/2 registry uses pass a label with no end punctuation (`registry/cobalt/ui/icon-button.tsx:67`, `registry/cobalt/ui/segmented-control.tsx:135`). Check: lint copy/casing and copy/end-punctuation on the tooltip slot (scripts/copy-check.mjs).
  - Don't: `<TooltipContent>Copy Link.</TooltipContent>`
  - Do: `<TooltipContent>Copy link</TooltipContent>`

### Anti-slop
- `rule/tooltip-not-on-text-buttons`: When a button has a visible label, give it no `Tooltip`, because repeating a label people can already read is noise, and the hover delay makes it a slow one. Evidence: app 2/2 registry uses put tooltips on icon-only controls and skip them when the option has a visible label (`registry/cobalt/ui/icon-button.tsx:66`, `registry/cobalt/ui/segmented-control.tsx:126-135`); principle heuristic: aesthetic and minimalist design. Check: review of every `TooltipTrigger` whose rendered control has visible text.
  - Don't: `<Tooltip><TooltipTrigger render={<Button />}>Save</TooltipTrigger><TooltipContent>Save your changes</TooltipContent></Tooltip>`
  - Do: `<Button>Save</Button>`
- `rule/tooltip-no-delay-override`: When a tooltip is built, pass no `delay` of its own and leave it to the provider's 400ms, instead of `delay={0}` or `delay={1000}`, because one delay across the app is what lets the hand learn when the name comes, and a 0ms tooltip flashes on every pass of the pointer. Evidence: measured 409ms with the provider, .design-system/evidence/tooltip/hover-1280.json; app 2/2 registry uses pass no delay (`registry/cobalt/ui/icon-button.tsx:46`, `registry/cobalt/ui/segmented-control.tsx:133`). Check: review of every `Tooltip` and `TooltipProvider` that passes `delay`.
  - Don't: `<Tooltip delay={0}>`
  - Do: `<Tooltip>`

### Limits
- `rule/tooltip-label-length`: When a label would run past 53 characters, shorten it to the control's name instead, because at 54 characters the 12px text wraps to a second line inside the 320px max width. Evidence: measured wrap at 54 characters in the 320px popup, .design-system/evidence/tooltip/hover-1280.json. Check: probe `.design-system/scripts/measure-overlays.mjs` grows the label on the showcase at 1280; lint copy/length on the tooltip slot (scripts/copy-check.mjs).
  - Don't: `<TooltipContent>Notifications from everyone in the workspace, grouped by day</TooltipContent>`
  - Do: `<TooltipContent>Notifications</TooltipContent>`

## Accessibility
Rests on Base UI `Tooltip`, which opens on hover and on focus, closes on leave, blur and Escape, and takes no focus; the trigger carries its own accessible name, since Base UI gives the popup no role and the trigger no `aria-describedby`. Every row that says `a11y scan` was read from the open tooltip on the live page into `.design-system/evidence/tooltip/hover-1280.json`.

### Keyboard
| Key | Where focus is | Effect | Focus after | Checked by |
|---|---|---|---|---|
| Tab | before the trigger | focuses the trigger and opens its tooltip after the delay | the trigger | a11y scan |
| Escape | the trigger with its tooltip open | closes the tooltip and nothing else, so a dialog around it stays (`trap/escape-nested`) | the trigger | by hand |
| Tab | the trigger with its tooltip open | moves to the next control and closes the tooltip; the next icon-only control opens its own | the next control | by hand |
| Enter or Space | the trigger | presses the control; the tooltip closes | wherever the control's action puts it | by hand |

### ARIA
| Part | Role | Accessible name from | States and properties | Announced | Checked by |
|---|---|---|---|---|---|
| trigger | button, or the radio the segmented control renders | its own `aria-label` or label, equal to the tooltip text | `data-popup-open` while the tooltip shows (`trap/open-trigger-unfocused`) | the name and role on focus; nothing extra when the tooltip opens | test |
| popup | none | none | `data-open`, `data-side`, `data-instant` for a neighbour | nothing; the tooltip is visual only | a11y scan |

## Tokens
| Part | State | Token |
|---|---|---|
| popup | all | `--tip` as the fill, `--tip-foreground` as the text, computed 18.0 to 1 in light and 14.4 to 1 in dark, `--edge` as the 1px ring, `--r-tooltip` (`--r-md`, and half a one-line tooltip's height under pill corners), `--t-press`, `--curve`, `--t-settle` and `--curve-settle` for the width |
| keys | with-shortcut | `--tip-foreground` at 70 percent, as the chart tooltip's quiet title, computed 9.1 to 1 on `--tip` in light and 7.8 to 1 in dark |
| provider | all | `TOOLTIP_DELAY_MS` from `registry/cobalt/lib/motion.ts`, 400ms |

## Related
- IconButton: the icon-only button that renders its one label as the name and the tooltip.
- Popover: text with a control in it, or more than a name.
- Button: a control with a visible label, which gets no tooltip.
- SegmentedControl: icon-only options named through tooltips.
- Dialog: a task that takes over the page.
