# Tooltip

## Usage

`Tooltip` shows a short hint next to a trigger on hover or keyboard focus. The trigger keeps its own behavior.

```vue
<script setup lang="ts">
import { Button } from '@astryx-vue/core/Button'
import { Tooltip } from '@astryx-vue/core/Tooltip'
</script>

<template>
  <Tooltip content="Save your changes">
    <Button label="Save" />
  </Tooltip>
</template>
```

### Anatomy

- **Tooltip surface**: Painted overlay surface that presents the tooltip.
- **Tooltip text**: Tooltip content rendered within the surface.

## Best practices

| Guidance | Practices |
| --- | --- |
| Do | Keep tooltip content concise: aim for under 140 characters of plain text. |
| Do | Add a tooltip to icon-only buttons and controls that lack a visible label. |
| Don't | Place interactive elements like links or buttons inside a tooltip; use HoverCard or Popover instead. |
| Don't | Use tooltips for essential information that users must see to complete a task. |

## Examples

### Action bar

Save, Cancel, and Delete, each with a hint above the button.

```vue
<script setup lang="ts">
import { Button } from '@astryx-vue/core/Button'
import { Center } from '@astryx-vue/core/Center'
import { HStack } from '@astryx-vue/core/Stack'
import { Tooltip } from '@astryx-vue/core/Tooltip'
</script>

<template>
  <Center>
    <HStack :gap="4">
      <Tooltip content="Save your changes" placement="above">
        <Button label="Save" />
      </Tooltip>
      <Tooltip content="Discard changes" placement="above">
        <Button label="Cancel" />
      </Tooltip>
      <Tooltip content="Delete permanently" placement="above">
        <Button label="Delete" variant="destructive" />
      </Tooltip>
    </HStack>
  </Center>
</template>
```

### Hook

A button named Using hook directly, with the hint Tooltip via hook.

```vue
<script setup lang="ts">
import { Button } from '@astryx-vue/core/Button'
import { Center } from '@astryx-vue/core/Center'
import { Tooltip } from '@astryx-vue/core/Tooltip'
</script>

<template>
  <Center>
    <Tooltip content="Tooltip via hook" placement="above" :delay="100">
      <Button label="Using hook directly" />
    </Tooltip>
  </Center>
</template>
```

### Inline text

privacy policy and terms of service sit in a sentence, each with its own hint.

```vue
<script setup lang="ts">
import { Text } from '@astryx-vue/core/Text'
import { Tooltip } from '@astryx-vue/core/Tooltip'
</script>

<template>
  <Text type="body">
    Learn more about our
    <Tooltip content="Your data is encrypted and never shared" placement="above">
      privacy policy
    </Tooltip>
    and
    <Tooltip content="Standard 30-day agreement" placement="above">
      terms of service
    </Tooltip>.
  </Text>
</template>
```

## Accessibility

The tooltip bubble is a separate layer, and the component links it to the trigger with ARIA attributes so assistive technology can announce both the extra description attached to the trigger and the text inside the bubble:

- The bubble has `role="tooltip"`, which tells assistive technology to treat it as a hint.
- The trigger receives `aria-describedby` pointing to the bubble's `id`.

The hint appears on mouse hover or keyboard focus. While it is showing, pressing Escape closes an uncontrolled tooltip; a controlled tooltip instead emits `openChange(false)`, and the parent decides whether to close it.

A press inside the open bubble stays in the bubble: a clickable card, list row, or tree row around the trigger does not activate. Page-level listeners still receive the press.

Because the hint appears only on hover or focus and disappears again, users can easily miss it, and touch devices do not always trigger it. Keep essential information that users must see to complete a task out of tooltips.

## Tooltip Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `content` | `string` | — | Tooltip text. Use the `content` slot for rich content. |
| `placement` | `'above' \| 'below' \| 'start' \| 'end'` | `'above'` | Side of the trigger. Flips when there is no room. |
| `alignment` | `'start' \| 'center' \| 'end'` | `'center'` | Alignment along the placement axis. |
| `delay` | `number` | `200` | Milliseconds before showing on hover. |
| `hideDelay` | `number` | `0` | Milliseconds before hiding. 0 uses a 100ms bridge so the pointer can reach the bubble. |
| `focusTrigger` | `'auto' \| 'always' \| 'never'` | `'auto'` | Whether focus shows the tooltip. auto listens only when the trigger is focusable. |
| `touchTrigger` | `'auto' \| 'tap' \| 'none'` | `'auto'` | Tap behavior on touch. auto skips buttons, links, and form controls. |
| `isEnabled` | `boolean` | `true` | Disables hover and focus triggers when false. |
| `hasHoverIndication` | `'auto' \| boolean` | `'auto'` | Dashed underline on a text-only trigger. auto applies it only to text. |
| `isOpen` | `boolean` | — | Controlled visibility. Hover and focus are ignored when set. |
| `isDefaultOpen` | `boolean` | `false` | Show on mount. |
| `anchorsOnSelf` | `boolean` | `false` | Skips the wrapper span so the slot root element is the trigger. Needed for headings and paragraphs. |
| `anchor` | `HTMLElement \| null` | — | External element used as the trigger. No wrapper is rendered, the default slot can be omitted, and focus, hover and `aria-describedby` are wired to that element. |

## Events

- `openChange(isOpen: boolean)`: fires when the tooltip shows or hides. With `isOpen`, it fires with `false` on Escape and the parent decides whether to close.

## Slots

- `default`: the trigger.
- `content`: rich tooltip content. Replaces the `content` prop text.

## Theme

```css
.my-tooltip {
  --astryx-tooltip-background: #000;
  --astryx-tooltip-foreground: #fff;
}
```

- `--astryx-tooltip-background`: bubble background.
- `--astryx-tooltip-foreground`: bubble text color.
- `--astryx-tooltip-indication-color`: dashed underline color.
- `--astryx-tooltip-z-index`: stacking order of the bubble.
