# Tooltip

Provide additional information when users hover over or focus on an element.

```tsx
import { Button, Tooltip } from '@fluxui-dev/react';
import { Cog6ToothIcon } from '@fluxui-dev/react/icons';

<Tooltip content="Settings">
    <Button icon={Cog6ToothIcon} iconVariant="outline" />
</Tooltip>
```

As a shorthand, you can pass a `tooltip` prop into a button component directly.

```tsx
<Button tooltip="Settings" ... />
```

To set the tooltip's options, pass a `Tooltip` without children instead. The button becomes its trigger.

```tsx
<Button tooltip={<Tooltip content="Settings" position="bottom" kbd="⌘," />} ... />
```

## Info tooltip

In cases where a tooltip's content is essential, you should make it `toggleable`. This way, users on touch devices will be able to trigger it on click/press rather than hover.

```tsx
import { Heading } from '@fluxui-dev/react';
import { InformationCircleIcon } from '@fluxui-dev/react/icons';

<Heading className="flex items-center gap-2">
    Tax identification number

    <Tooltip toggleable>
        <Button icon={InformationCircleIcon} size="sm" variant="ghost" aria-label="More information" />

        <Tooltip.Content className="max-w-[20rem] space-y-2">
            <p>For US businesses, enter your 9-digit Employer Identification Number (EIN) without hyphens.</p>
            <p>For European companies, enter your VAT number including the country prefix (e.g., DE123456789).</p>
        </Tooltip.Content>
    </Tooltip>
</Heading>
```

## Position

Position tooltips around the element for optimal visibility. Choose from `top`, `right`, `bottom`, or `left`.

```tsx
<Tooltip content="Settings" position="top">
    <Button icon={Cog6ToothIcon} iconVariant="outline" />
</Tooltip>

<Tooltip content="Settings" position="right">
    <Button icon={Cog6ToothIcon} iconVariant="outline" />
</Tooltip>

<Tooltip content="Settings" position="bottom">
    <Button icon={Cog6ToothIcon} iconVariant="outline" />
</Tooltip>

<Tooltip content="Settings" position="left">
    <Button icon={Cog6ToothIcon} iconVariant="outline" />
</Tooltip>
```

## Reference

### Tooltip

Renders no element of its own and uses its first element child as the trigger, which must accept a `ref` and pass the props it receives to its element (such as Flux `Button`, `a`). Tooltip passes the props and ref it receives on to that child, so it can sit inside `Modal.Trigger` or `Dropdown.Trigger` as well as around them.

**Prop:**

- `content` - Text content to display in the tooltip. Alternative to using the `Tooltip.Content` component.
- `position` - Position of the tooltip relative to the trigger element. Options: `top` (default), `right`, `bottom`, `left`.
- `align` - Alignment of the tooltip. Options: `center` (default), `start`, `end`.
- `disabled` - Prevents user interaction with the tooltip.
- `gap` - Spacing in pixels between the trigger element and the tooltip. Default: `5`.
- `offset` - Offset in pixels of the tooltip from the trigger element. Default: `0`.
- `toggleable` - Makes the tooltip clickable instead of hover-only. Useful for touch devices.
- `interactive` - Uses the proper ARIA attributes (`aria-expanded` and `aria-controls`) to signal that the tooltip has interactive content.
- `kbd` - Keyboard shortcut hint displayed at the end of the tooltip.
- `open` - Controlled open state of the tooltip. Pair with `onOpenChange`.
- `defaultOpen` - Initial open state of the tooltip when uncontrolled.
- `onOpenChange` - Callback fired when the tooltip opens or closes, receiving the new open state and `eventDetails`, whose `reason` tells why.

**Attribute:**

- `data-flux-tooltip` - Applied to the trigger element (not a wrapper) for styling and identification.

### Tooltip.Content

**Prop:**

- `kbd` - Keyboard shortcut hint displayed at the end of the tooltip content.

**CSS:**

- `className` - CSS classes applied to the tooltip's content element, such as a max width.

**Attribute:**

- `data-flux-tooltip-content` - Applied to the tooltip's content element.
