<!--
  GENERATED FILE - do not edit by hand.
  Source of truth: src/components/mds-tooltip/ in the magma monorepo (usage/*.md and the
  component's JSDoc). Regenerated on every stencil build (scripts/component-docs.ts).
-->

# mds-tooltip

> `@maggioli-design-system/magma` 2.15.0. Shadow DOM: style it only through the public CSS custom properties and the parts below.

The `<mds-tooltip>` web component is the floating contextual hint of the Magma Design System. It renders a small text bubble that attaches to a separate trigger element identified by a CSS selector, rather than relying on the native `title` attribute.

#### Semantic Behavior

- **Detached trigger model**: The tooltip is not wrapped around its trigger; the required `target` selector is resolved and the component binds itself to the first matching caller.
- **Hover and focus visibility**: The bubble shows while the pointer is over the trigger or the trigger has a focus the browser rings (`:focus-visible`, the focus of the keyboard), and hides when neither holds; Escape hides it until the trigger is hovered or focused again. The focus of a click, or one a script moves to the trigger after a click, does not keep it open: it closes when the pointer leaves. The tooltip takes `role="tooltip"` and, when it shares a DOM tree with the trigger, writes `aria-describedby` on it, or `aria-labelledby` with `relation="label"`; an attribute the trigger already has is left alone.
- **Visibility is the source of truth**: Setting `visible` programmatically shows or dismisses the bubble, allowing the tooltip to be controlled without a hover.
- **Live repositioning**: Changing any layout prop (`placement`, `offset`, `disableShift`, `shiftPadding`, `strategy`, `flip`, `disableAutoPlacement`) recomputes the floating position on the fly.
- **Text-only default slot**: The default slot is meant for a plain text string (exposed as the `text` shadow part); HTML elements or components should not be slotted in.

#### Properties & Visual Configurations

- **`target`** (required) is the CSS selector of the trigger element the tooltip listens to and anchors against; the first match wins.
- **`placement`** chooses the preferred side and alignment relative to the caller (e.g. `'top'`, `'bottom-start'`), taken whenever it has room; by default the tooltip moves to the opposite side, then to the sides across, only when it does not fit there (**`disableAutoPlacement`** opts out and pins to `placement`, and **`flip`** then allows the fallback to the opposite side only).
- the bubble is kept inside the viewport by default (**`disableShift`** opts out), with **`shiftPadding`** reserving a safe gap from the viewport edges; **`offset`** sets the distance between the bubble and the caller.
- **`strategy`** selects the CSS positioning strategy: `'fixed'` (default) escapes clipping ancestors, `'absolute'` anchors within the nearest positioned ancestor.
- **`relation`** says what the tooltip is to its trigger: its `'description'` (default, `aria-describedby`), or its `'label'` (`aria-labelledby`), when the tooltip text is the only visible name of the trigger, as on an icon-only button. Changing it moves the attribute on the trigger.
- **`typography`** picks the text scale of the bubble (`'tip'`, `'caption'`, `'detail'`), where `'tip'` is the default compact hint sizing.

## Read next

- [`examples.md`](examples.md) - correct usage, from the most common case
- [`mistakes.md`](mistakes.md) - the wrong forms, each with the right one
- [Storybook](https://magma-design-system.github.io/magma/storybook/?path=/docs/ui-tooltip--docs) - the live examples, in the published Storybook of `main`
- [`conventions.md`](../../../../agents/conventions.md), [`variants.md`](../../../../agents/variants.md), [`mistakes.md`](../../../../agents/mistakes.md) - the rules shared by every component

## Props

| Prop | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `disableAutoPlacement` | `disable-auto-placement` | `boolean` | `false` | Pins the component to `placement`: without it, the component moves to another side of the caller when `placement` has no room. |
| `disableShift` | `disable-shift` | `boolean` | `false` | If set, the component will not be kept inside the viewport. |
| `flip` | `flip` | `boolean` | `false` | With `disableAutoPlacement`, moves the component to the opposite side of the caller when `placement` has no room. Auto-placement, the default, already does it. |
| `offset` | `offset` | `number` | `12` | Sets distance between the tooltip and the caller. |
| `placement` | `placement` | `"bottom" \| "bottom-end" \| "bottom-start" \| "left" \| "left-end" \| "left-start" \| "right" \| "right-end" \| "right-start" \| "top" \| "top-end" \| "top-start"` | `'top'` | Specifies where the component should be placed relative to the caller: the side it takes whenever it has room there. |
| `relation` | `relation` | `"description" \| "label"` | `'description'` | Sets what the tooltip is to its caller: its `description` (`aria-describedby`), or its `label` (`aria-labelledby`), when the tooltip holds the only visible name of the caller, as on an icon-only button. |
| `shiftPadding` | `shift-padding` | `number` | `12` | Sets a safe area distance between the tooltip and the viewport. |
| `strategy` | `strategy` | `"absolute" \| "fixed"` | `'fixed'` | Sets the CSS position strategy of the component. |
| `target` | `target` | `string` | - | **Required**. Specifies the selector of the target element, this attribute is used with `querySelector` method. |
| `typography` | `typography` | `"caption" \| "detail" \| "tip"` | `'tip'` | Specifies the font typography of the element |
| `visible` | `visible` | `boolean` | `false` | Specifies the visibility of the component. |

## Slots

| Slot | Description |
| --- | --- |
| (default) | Add `text string` to this slot, **avoid** to add `HTML elements` or `components` here. |

## Parts

| Part | Description |
| --- | --- |
| `text` | The text of the tooltip, around the default slot |

## CSS custom properties

| Property | Description |
| --- | --- |
| `--mds-tooltip-background` | Background color of the tooltip body. |
| `--mds-tooltip-delay` | Delay before showing the tooltip. |
| `--mds-tooltip-z-index` | z-index of the tooltip container. |

Only these are public. Its other 7 are internal: they may change in any release, do not set them.

## Dependencies

Uses: `mds-text`.
Used by: `mds-help`, `mds-keyboard`, `mds-radial-menu-item`.
