# Tooltip

A short hint for a control on hover and keyboard focus, and on tap for touch users when needed.

- Family: overlay
- Import: `import { Tooltip } from "@senvenli/react/overlay";`
- Page: https://design.senvenli.com/docs/components/tooltip
- JSON: https://design.senvenli.com/docs/components/tooltip.json

## Example: Naming an icon button

The same words as the button's aria-label, on hover and keyboard focus.

```tsx
import { Button } from "@senvenli/react/action";
import { Stack } from "@senvenli/react/layout";
import { Tooltip } from "@senvenli/react/overlay";

export default function Example() {
  return (
    <Stack direction="horizontal" space="space-050">
      <Tooltip content="Edit">
        <Button variant="subtle" iconOnly iconBefore="pencil" aria-label="Edit" />
      </Tooltip>
      <Tooltip content="Duplicate">
        <Button variant="subtle" iconOnly iconBefore="copy" aria-label="Duplicate" />
      </Tooltip>
      <Tooltip content="Archive">
        <Button variant="subtle" iconOnly iconBefore="archive" aria-label="Archive" />
      </Tooltip>
    </Stack>
  );
}
```

## Examples

### With a shortcut

The key that does the same thing, as a chip.

```tsx
import { Button } from "@senvenli/react/action";
import { Tooltip } from "@senvenli/react/overlay";

export default function Example() {
  return (
    <Tooltip content="Filter" shortcut="F">
      <Button iconOnly iconBefore="list-filter" aria-label="Filter" />
    </Tooltip>
  );
}
```

### Placement

Above by default; it flips when there is no room.

```tsx
import { Button } from "@senvenli/react/action";
import { Stack } from "@senvenli/react/layout";
import { Tooltip } from "@senvenli/react/overlay";

const PLACEMENTS = ["top", "bottom", "start", "end"] as const;

export default function Example() {
  return (
    <Stack direction="horizontal" space="space-100">
      {PLACEMENTS.map((placement) => (
        <Tooltip key={placement} content={`Placed at the ${placement}`} placement={placement}>
          <Button>{placement}</Button>
        </Tooltip>
      ))}
    </Stack>
  );
}
```

### Readable on touch

With openOnTouch a tap opens it, for a status that has no action of its own.

```tsx
import { Badge } from "@senvenli/react/display";
import { Tooltip } from "@senvenli/react/overlay";

export default function Example() {
  return (
    <Tooltip content="Waiting for the bank to confirm the payment" openOnTouch>
      <Badge tone="warning">Payment pending</Badge>
    </Tooltip>
  );
}
```

## Guidelines

### When to use it

- Naming an icon button or adding a short hint.

### Use something else when

- [popover](https://design.senvenli.com/docs/components/popover.md): The content is interactive or long.
- [hover-card](https://design.senvenli.com/docs/components/hover-card.md): The hint is rich content, such as a profile, and opens from a link.

## Accessibility

Built in:

- Opens on keyboard focus too; touch users can tap with openOnTouch.

You provide:

- Content that is a hint, never the only place important information lives.

## API reference

### Tooltip

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| content | `string` |  | yes | Plain text only: the same words as the control's `aria-label`, or a truncated value in full. |
| children | `ReactElement<unknown, string \| JSXElementConstructor<any>>` |  | yes | The trigger. It must be focusable; a non-interactive element (a truncated lozenge) is made focusable. |
| placement | `Placement` |  | no |  |
| shortcut | `string` |  | no | A keyboard shortcut shown as a chip ("F"). |
| openOnTouch | `boolean` |  | no | Readable on touch screens: a tap on the trigger opens the tooltip and a second tap closes it; a tap anywhere else, or Esc, closes it. Mouse hover and keyboard focus work exactly as without it. For a trigger that does nothing on its own (a country flag, a truncated value); on a button the tap still presses it. |
| motion | `ComponentMotion` |  | no | `auto` (follow the device), `reduce` or `none`, for this component; the provider's setting otherwise. |

### Tokens it reads

`--ds-background-neutral-bold`, `--ds-background-neutral-pressed`, `--ds-background-neutral-subtle-hovered`, `--ds-blanket`, `--ds-border`, `--ds-border-focused`, `--ds-easing-enter`, `--ds-easing-exit`, `--ds-icon-danger`, `--ds-icon-subtle`, `--ds-radius-large`, `--ds-radius-small`, `--ds-radius-xlarge`, `--ds-shadow-overlay`, `--ds-space-050`, `--ds-space-075`, `--ds-space-100`, `--ds-space-150`, `--ds-space-200`, `--ds-space-300`, `--ds-surface-overlay`, `--ds-text`, `--ds-text-danger`, `--ds-text-disabled`, `--ds-text-inverse`, `--ds-text-subtle`, `--ds-text-subtlest`, `--font-ds-mono`

## Related

- [popover](https://design.senvenli.com/docs/components/popover.md)
