# Tooltip

A hint on hover and focus, never a label and never interactive.

Live variants: https://design.arcadia.is/components/tooltip

```tsx
import { Tooltip, TooltipProvider } from "@arcadia/ui";
```

## When to use

- An icon-only control's name in a few words
- A control's shortcut beside its name
- One short fact about a control

## When not to use

- Anything a person must read at leisure or click: use `Popover`
- A preview of what a link points to: use `HoverCard`
- A list of actions or choices: use `Menu`

## In context

Hover or focus a copy action to preview the value.

```tsx
import { useState } from "react";
import { copyText, IconButton, Toolbar, Tooltip } from "@arcadia/ui";

function MessageTooltips() {
  const [result, setResult] = useState("");
  const copy = async (value: string, label: string) => {
    setResult(await copyText(value) ? label + " copied" : "Couldn't copy " + label.toLowerCase());
  };
  return (
    <div {...sx("cmp-bar", cmp.bar)}>
      <Toolbar aria-label="Repository actions" rootStyle={cmp.toolbarCompact} leading={
        <div {...sx("cmp-toolbar", cmp.toolbar)}>
          <Tooltip content="Copy repository path" subtitle="arcadia/design" side="bottom">
            <IconButton icon="copy" label="Copy repository path" tooltip={false} onClick={() => void copy("arcadia/design", "Path")} />
          </Tooltip>
          <Tooltip content="Copy revision" subtitle="a74f21c" side="bottom">
            <IconButton icon="branch" label="Copy revision" tooltip={false} onClick={() => void copy("a74f21c", "Revision")} />
          </Tooltip>
        </div>
      } />
      <span {...sx("cmp-result", cmp.result)} role="status">{result}</span>
    </div>
  );
}
```

Copy a path to see the clipboard feedback.

```tsx
import { CopyButton } from "@arcadia/ui";

<CopyButton iconOnly label="Copy sample path" text="arcadia/design" />
```

## Usage

```tsx
import { Button, Tooltip } from "@arcadia/ui";

<Tooltip content="Open in editor" shortcut="mod+o">
  <Button iconEnd="external">Editor</Button>
</Tooltip>
```

A hint, never a label and never interactive: icon-only controls carry their own `aria-label`. It opens after 350ms and closes after 100ms; once one has shown, its neighbours open instantly for 200ms, so reading along a toolbar doesn't wait at every button. Mount `TooltipProvider` once for that grouping. IconButton draws its own tooltip from `label` and `shortcut`.

Which overlay? A Tooltip names a control or a target in a few words: a name, a path, a one-line summary. A [Hover Card](/components/popover#hover-card) previews what a link points to, a [Popover](/components/popover) holds content you act on, and a [Menu](/components/menu) lists actions or choices.

## Examples

### Anatomy

A title, a trailing Caption shortcut and an optional subtitle, on any side. Rendered open in place.

- Top, the default: a title and glyph keys
- Right: a subtitle on a second line
- Bottom: a word shortcut as text
- Left: a status and its detail

### Length

Keep a tooltip to a few words. Put longer explanations in the interface.

```tsx
import { Button, Tooltip } from "@arcadia/ui";

<Tooltip content={SUMMARY}>
  <Button variant="ghost">Build check</Button>
</Tooltip>
```

Use a [Popover](/components/popover) for a prompt, a longer message or a list.

## Customising

`rootStyle` takes where the tooltip's popup sits and its widest width.

- `--tooltip-max-w` (`TokenRef<Measure>`, default `280px`)

## Accessibility

It shows on keyboard focus as well as hover and describes its trigger; the trigger's own name stays its label. It holds no focusable content, so anything a person must read at leisure or click belongs in a [Popover](/components/popover). The pointer passes through it, so it never takes a press or a hover from what it covers.

- Esc: Hides the tooltip

## API reference

### Tooltip

- `content` (`ReactNode`, required)
- `shortcut` (`ShortcutSpec`): A keyboard shortcut: display keys (`["⌘", "K"]`), a glyph string (`"⇧⌘D"`, `"Esc"`) or a spec (`"mod+shift+k"`), as understood by `shortcutKeys()` in kbd.tsx.
- `subtitle` (`ReactNode`)
- `lines` (`number`)
- `side` (`"top" | "bottom" | "left" | "right" | "inline-start" | "inline-end"`, default `"top"`)
- `block` (`boolean`, default `false`)
- `align` (`"start" | "center" | "end"`, default `"center"`)
- `sideOffset` (`number`, default `6`)
- `delay` (`number`)
- `closeDelay` (`number`)
- `disabled` (`boolean`)
- `open` (`boolean`)
- `defaultOpen` (`boolean`)
- `onOpenChange` (`(open: boolean) => void`)
- `container` (`PortalContainer`): Where a surface's portal mounts. Default: `document.body`. Pass a themed subtree to keep its `data-theme`, or a transformed stage to contain `position: fixed` overlays (previews): a modal set down in one stays in it, shown in place, out of the browser's top layer.
- `rootStyle` (`RootStyle<TooltipKnobs>`)

### TooltipProvider

- `delay` (`number`, default `350`)
- `closeDelay` (`number`, default `100`)
- `timeout` (`number`, default `200`)
