> A guide to [@fabiocv/ui](https://ui.fabio.cv/). Every guide is listed at https://ui.fabio.cv/llms.txt.

# Tooltip

A [Base UI Tooltip](https://base-ui.com/react/components/tooltip) that follows
the pointer, exported from `@fabiocv/ui/tooltip`.

```tsx
import { Tooltip, TooltipGroup } from '@fabiocv/ui/tooltip';

<Tooltip content="House of Maserati">
  <button type="button">Maserati</button>
</Tooltip>;

<TooltipGroup>
  <Tooltip content="House of Maserati">
    <button type="button">Maserati</button>
  </Tooltip>
  <Tooltip content="Bentayga online configurator">
    <button type="button">Bentley</button>
  </Tooltip>
</TooltipGroup>;
```

`children` is the trigger. It must be one element that can take focus.

- One line of menu text, `14px` on a `20px` line, with `8px` horizontal padding
  and `4px` corners. Surface ink on Foreground muted.
- Moves on springs given in Apple's terms, a response and a damping ratio:
  `0.15s` and `0.86` to trail the pointer, quick with a trace of give, `0.25s`
  and `1` to show and hide, and `0.4s` and `1` to resize. The last two settle
  without overshooting.
- Shows as soon as the pointer enters, fading in as it moves `4px` away from
  the pointer. Its width grows from `24px` away from its aligned side on the
  show spring, its edges moving on transforms while the text stays put. As soon
  as the pointer leaves, it fades out back the same way, from wherever the
  fade-in had got to. With reduced motion it only fades.
- Sits `16px` below the pointer with its left edge `16px` to its right, and
  shifts or flips to stay `16px` clear of the viewport's edges. Keyboard focus
  centres it `16px` below the trigger.
- Trails the pointer on one spring per axis, on transforms. It opens in place,
  and focus and reduced motion move it at once.
- Fits its text, up to `--container-tooltip` or the room left in the viewport.
- Text that does not fit waits `600ms`, then scrolls left at `24px/s` in a loop,
  `24px` between copies, and crops at the box's edges. With reduced motion it
  stays still.
- Tooltips inside a `TooltipGroup` share one popup. It stays open as the pointer
  or focus moves from one trigger to the next. The new text replaces the old at
  once and stays put while the box's edges spring from the width it showed to
  the new one, on transforms, holding the aligned side still. The text crops at
  the edges. With reduced motion the width changes at once.

## Types of `@fabiocv/ui/tooltip`

```ts
/**
 * Tooltips inside share one popup. It stays open as the pointer or focus
 * moves between their triggers, and resizes to the new content.
 */
export declare function TooltipGroup({ children }: {
    children: ReactNode;
}): import("react").JSX.Element;

export type TooltipProps = {
    /** One line of text. It scrolls when it does not fit. */
    content: ReactNode;
    /** The element that shows the tooltip. It must be able to take focus. */
    children: ReactElement;
};

/**
 * A Base UI tooltip that follows the pointer. Keyboard focus centres it below
 * its trigger. Outside a `TooltipGroup` it has a popup of its own.
 */
export declare function Tooltip({ content, children }: TooltipProps): import("react").JSX.Element;
```

## Examples

### Default

```tsx
<Tooltip content="House of Maserati"><Button>Maserati</Button></Tooltip>
```

### Overflow

```tsx
<Tooltip content="House of Maserati, a brand experience across Europe"><Button>Maserati</Button></Tooltip>
```

### Group

```tsx
<TooltipGroup>
  <Tooltip content="Nike By You configurator"><Button>Nike</Button></Tooltip>
  <Tooltip content="House of Maserati"><Button>Maserati</Button></Tooltip>
  <Tooltip content="Bentayga online configurator"><Button>Bentley</Button></Tooltip>
</TooltipGroup>
```

See it at https://ui.fabio.cv/tooltip/.
