# Tooltip

A short text label that appears on hover and keyboard focus. Use it to name icon-only buttons or add a brief hint; put anything longer or interactive in a popover.

- Package: [@vigdx/ui](https://www.npmjs.com/package/@vigdx/ui)
- Selectors: `[vigTooltip]`
- Source: [libs/ui/src/lib/atoms/tooltip/tooltip.ts](https://github.com/bakyurekk/vigdx/blob/main/libs/ui/src/lib/atoms/tooltip/tooltip.ts)

```typescript title="Import"
import { Tooltip } from '@vigdx/ui/tooltip';
```

## Basic

Add `vigTooltip` with the text to any focusable element or to a component wrapping one, such as `vig-button`. Icon-only buttons still need an `ariaLabel`: the tooltip only describes, it does not name.

```typescript title="tooltip-basic.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Button, ButtonIcon } from '@vigdx/ui/button';
import { Icon } from '@vigdx/ui/icon';
import { Tooltip } from '@vigdx/ui/tooltip';

@Component({
  selector: 'app-tooltip-basic',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Button, ButtonIcon, Icon, Tooltip],
  template: `
    <div class="flex flex-wrap items-center gap-3">
      <!-- Icon-only: the aria-label names the button, the tooltip shows the name. -->
      <vig-button variant="secondary" ariaLabel="Upload" vigTooltip="Upload">
        <vig-icon vigButtonIcon name="upload" />
      </vig-button>
      <vig-button variant="secondary" ariaLabel="Search" vigTooltip="Search">
        <vig-icon vigButtonIcon name="search" />
      </vig-button>

      <!-- With a visible label the tooltip adds a description. -->
      <vig-button label="Publish" vigTooltip="Visible to everyone with the link" />
    </div>
  `,
})
export class TooltipBasicDemo {}
```

## Positions

`vigTooltipPosition` sets the preferred side: `top` (default), `end`, `bottom` or `start`; `start` and `end` follow the text direction (the deprecated `left` and `right` are physical sides). Without room the tooltip flips to the opposite side.

```typescript title="tooltip-positions.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Button } from '@vigdx/ui/button';
import { Tooltip, type TooltipPosition } from '@vigdx/ui/tooltip';

@Component({
  selector: 'app-tooltip-positions',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Button, Tooltip],
  template: `
    <div class="flex flex-wrap items-center justify-center gap-3 py-6">
      @for (position of positions; track position) {
        <vig-button
          variant="secondary"
          [label]="position"
          [vigTooltip]="'Tooltip at the ' + position"
          [vigTooltipPosition]="position"
        />
      }
    </div>
  `,
})
export class TooltipPositionsDemo {
  protected readonly positions: TooltipPosition[] = ['top', 'end', 'bottom', 'start'];
}
```

## Disabled and non-interactive hosts

`vigTooltipDisabled` turns the tooltip off without removing it. On a non-interactive element add `tabindex="0"`, so keyboard users can reach the tooltip too.

```typescript title="tooltip-disabled.ts"
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { Badge } from '@vigdx/ui/badge';
import { ToggleSwitch } from '@vigdx/ui/toggle-switch';
import { Tooltip } from '@vigdx/ui/tooltip';

@Component({
  selector: 'app-tooltip-disabled',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Badge, Tooltip, ToggleSwitch],
  template: `
    <vig-toggle-switch label="Show hints" [(value)]="hints" />
    <div class="flex flex-wrap items-center gap-3 text-sm">
      Build status:
      <!-- A non-interactive element needs tabindex="0" to show its tooltip on focus. -->
      <span
        tabindex="0"
        class="rounded-full focus:outline-hidden focus-visible:shadow-(--shadow-focus-ring)"
        vigTooltip="Last run 4 minutes ago, 212 tests"
        [vigTooltipDisabled]="!hints()"
      >
        <vig-badge label="Passing" variant="success" [dot]="true" />
      </span>
    </div>
  `,
})
export class TooltipDisabledDemo {
  protected readonly hints = signal(true);
}
```

## Styling hooks

Internal elements carry a stable `data-part` and the component's `data-scope`; both are public API, so removing one is a breaking change. Select a part by both, e.g. `[data-scope="tooltip"][data-part="panel"] { … }`: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through `aria-*` and, where listed, a `data-state`; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other `data-*` attributes listed below (such as `data-opening` while an overlay animates) are API too. See [Customizing](https://vigdx.com/docs/theming.md#customizing).

Scope: `[data-scope="tooltip"]`

| Part | Element | data-state |
| --- | --- | --- |
| `panel` | The `role="tooltip"` bubble, rendered in the overlay container. |   |

| Attribute | Meaning |
| --- | --- |
| `data-tooltip-trigger` | On the trigger of an active tooltip (with text, not disabled): the `id` of its bubble, which exists while the tooltip is shown. |

## Accessibility

- Follows the WAI-ARIA APG tooltip pattern: the panel has `role="tooltip"`. The text is wired from the first render, before any hover or focus, so screen-reader users browsing the page get it too: it describes the trigger (`aria-describedby`), names a trigger that has no name of its own (`aria-labelledby`), and is left out when it only repeats the trigger's name. A name from a `<label>`, a button's `value`, an image's `alt` or a `placeholder` counts. The hidden copy sits in one container at the end of the page (or of the enclosing dialog), never inside or beside the trigger; on a kit form field it joins the field's hint and error, so it stays when they change.
- Shows on hover and on keyboard focus, but not on focus that follows a click. Escape hides it without moving focus or the pointer, wherever focus is; that press only dismisses the tooltip, so it never also closes a surrounding dialog.
- The panel itself can be hovered, so moving the pointer onto it keeps it open (WCAG 1.4.13, content on hover or focus).
- Tooltips are not reachable on touch screens and are read as descriptions: never put essential information or interactive content in them.

## API

### Tooltip

Selector: `[vigTooltip]` · Kind: directive

Text tooltip on hover and keyboard focus, dismissable with Escape wherever focus is (WCAG 1.4.13): that press closes only the tooltip, not a surrounding dialog.

The text is also kept in a hidden element from the first render, so assistive tech has it before any interaction (a browse-mode screen reader never hovers): it describes the trigger (`aria-describedby`), names a trigger that has no name of its own (`aria-labelledby`), and is left out when it only repeats the trigger's name. On a kit form field the reference joins the field's own descriptions, so a hint or error appearing later keeps it; on other elements a rewritten attribute gets it back.

**Example :**

```html
<vig-button vigTooltip="Satırı sil" vigTooltipPosition="start" … />
```

The bubble renders in the overlay container as `[data-scope="tooltip"][data-part="panel"]`. While the tooltip has text and is not disabled, the trigger carries `data-tooltip-trigger` set to the bubble's `id` (the bubble exists only while shown), which `TooltipHarness` (`@vigdx/ui/testing`) follows. panel tooltip data-tooltip-trigger

#### Inputs

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `vigTooltip` | `string` | `''` | — |
| `vigTooltipDisabled` | `boolean` | `false` | — |
| `vigTooltipPosition` | `TooltipPosition` | `'top'` | — |
