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

# mds-toast

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

The `<mds-toast>` web component is the transient notification surface of the Magma Design System, used to surface brief, non-blocking feedback messages that appear over the viewport and auto-dismiss after a timeout. It has no native HTML equivalent and orchestrates its own visibility, positioning, and auto-close lifecycle.

#### Semantic Behavior

- **Announced**: The host is a status region (`role="status"`): the message is read out when the toast shows it, without moving the focus. While not visible, the message is hidden from assistive technologies too, not only moved out of the viewport. Inside an `<mds-toast-region>` the region is the status region and the toast has no role of its own.
- **Inside a region**: In an `<mds-toast-region>` the toast is laid out by the region, in a column with the other toasts visible at the same time, instead of being fixed at its edge on its own; the region gives it its `position`. A hidden toast in a region takes no room once its exit is over, and its entrance and exit are a short fade towards the edge.
- **Auto-dismiss timer**: When `visible` is true and `duration` is a positive number, an internal timer counts down and then sets `visible` back to `false`; setting `duration` to `0` (or falsy) keeps the toast on screen until it is closed intentionally.
- **The timer waits for the person**: The countdown stops while the pointer is over the toast or the focus is inside it (on its action, on its hide button), and goes on with the time that was left once both have left: the toast does not take its action away while the person is reading it or reaching the action.
- **Hide button**: With `dismissible`, the toast shows at its end a button with an arrow towards the edge it leaves by (down at the bottom, up at the top), named in the current language and reachable with the keyboard; it hides the toast. It is an arrow and not a cross because the action next to it may itself be a cancel ("Annulla"): the arrow only sends the message away.
- **Close event**: Whenever the toast hides, the component emits `mdsToastClose` once, after the outro animation - consumers should listen for this to remove the toast from the DOM or update queue state. The `reason` of its detail says who hid it: `timeout` (the `duration` ran out), `close` (the person, with the hide button) or `hide` (your code removed `visible`). A toast shown again before the outro is over emits nothing for that hiding.
- **Reactive timer**: Showing the toast again (`visible` back to true) or changing `duration` at runtime restarts the countdown; hiding it stops the countdown, so a toast hidden by your code closes once, as `hide`, and never again as `timeout`.
- **Conditional regions**: The text region renders only when the host has inner content, and the action region is shown only while a `[slot="action"]` child is present, following the children added or removed later - empty slots produce no layout.
- **Default-slot is text**: The default slot is intended for a plain text string only; icons go in the `icon` slot and interactive controls in the `action` slot.

#### Properties & Visual Configurations

The shared `variant` / `tone` ladders are defined in [`agents/variants.md`](../../../../agents/variants.md); `<mds-toast>` consumes the theme variant set and the minimal tone set (`'strong'` / `'weak'`) without adding component-specific values.

#### Other behavioral props

- **`position`** anchors the toast to one of the six viewport corners/edges (top or bottom, left/center/right), driving both placement and the direction of the entry/exit animation; pick the edge that matches where users expect ephemeral feedback to surface.
- **`visible`** is the controlled on/off switch for the toast; toggling it drives the show/hide animation and the auto-dismiss timer rather than mounting or unmounting the element.
- **`duration`** is the visibility window in milliseconds before auto-dismiss; use a longer value for messages that carry an action the user must reach, and `0` for toasts that must stay until explicitly closed.
- **`dismissible`** shows the hide button; give it to a toast that stays (`duration="0"`) when its action is not what every person wants ("Riprova"), so the person can send the message away without using it.
- **`deletable`** is the old name of `dismissible`, deprecated: the button dismisses the message, it deletes nothing. It still works, and goes in the next major.

#### Slots

- **`icon`** holds a leading glyph (recommended `mds-icon`); **`action`** holds interactive follow-ups (recommended `mds-button`) and, when present, renders inside a dedicated actions container.

## 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-toast--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 |
| --- | --- | --- | --- | --- |
| `deletable` | `deletable` | `boolean \| undefined` | - | **Deprecated**: Use `dismissible`: the button dismisses the message, it deletes nothing. Goes in the next major. Shows the hide button, as `dismissible` does. |
| `dismissible` | `dismissible` | `boolean \| undefined` | - | Shows a button that hides the toast, an arrow towards the edge the toast leaves by |
| `duration` | `duration` | `number \| undefined` | `5000` | If set, specifies the visibility duration in milliseconds of the element inside the viewport, when the time is up the visible property will be set to false. The countdown waits while the pointer is over the toast or the focus is inside it. If the duration is set to 0 the toast stays until it is hidden: give it `dismissible` so the person can hide it too. |
| `position` | `position` | `"bottom-center" \| "bottom-left" \| "bottom-right" \| "top-center" \| "top-left" \| "top-right"` | `'bottom-center'` | Sets position of toast |
| `tone` | `tone` | `"strong" \| "weak" \| undefined` | `'strong'` | Sets the tone of the color variant |
| `variant` | `variant` | `"ai" \| "dark" \| "error" \| "info" \| "light" \| "primary" \| "success" \| "warning" \| undefined` | `'light'` | Sets the theme variant colours |
| `visible` | `visible` | `boolean \| undefined` | - | Specifies if toast is visible at the bottom or not |

## Events

| Event | Detail | Description |
| --- | --- | --- |
| `mdsToastClose` | `MdsToastCloseEventDetail` | Emits once the toast is hidden and its exit animation is over, whoever hid it: the `reason` of the detail says who, `timeout`, `close` (the person, with the hide button) or `hide` (the application) |

## Slots

| Slot | Description |
| --- | --- |
| (default) | Add `text string` to this slot, **avoid** to add `HTML elements` or `components` here. |
| `action` | Add `HTML elements` or `components`, it is **recommended** to use `mds-button` element. |
| `icon` | Insert an icon image, it can be `HTML elements` or `components`, it is **recommended** to add `mds-icon` element. |

## CSS custom properties

| Property | Description |
| --- | --- |
| `--mds-toast-background` | Background color of the toast component. |
| `--mds-toast-color` | Text color inside the toast. |
| `--mds-toast-shadow` | Shadow applied to the toast container. |
| `--mds-toast-width` | Width of the toast component. |

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

## Dependencies

Uses: `mds-text`, `mds-button`.
