<!-- index: /slotted/llms.txt -->
# alert

`data-ui="alert"` · Framed notice heading a section, a form or a page.

## Import

```tsx
import {
  Alert,
  AlertActions,
  AlertContent,
  AlertDefaultsProvider,
  AlertDescription,
  AlertTitle,
} from '@slotted/react';
```

## Minimal example

Example

```tsx
import { Alert, AlertContent, AlertDescription, AlertTitle } from '@slotted/react/alert';

export default function AlertBasic() {
  return (
    <Alert>
      <AlertContent>
        <AlertTitle>Spring price list is live</AlertTitle>
        <AlertDescription>
          The new prices took effect for 1,240 products at 6:00 AM.
        </AlertDescription>
      </AlertContent>
    </Alert>
  );
}
```

## Anatomy

| Part | Element | Required |
| --- | --- | --- |
| `root` | section | yes |
| `icon` | span | no |
| `content` | div | yes |
| `title` | div, or the element render returns | no |
| `description` | p, or the element render returns | no |
| `actions` | div | no |
| `dismiss` | button | no |

## Props

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `tone` | `'accent' \| 'secondary' \| 'info' \| 'success' \| 'warning' \| 'danger'` | accent | Alert | Which of the six tones the message speaks in, and which mark it draws: status-info for accent and info, none for secondary, status-success, status-warning, status-danger. |
| `variant` | `'soft' \| 'outline' \| 'solid'` | soft | Alert | How that color is painted. soft carries the tone’s surface and its border, outline the border alone, solid the tone’s fill and the ink the theme measures against it. |
| `reach` | `'inline' \| 'section' \| 'page'` | section | Alert | The scope the message applies to. inline is tightest and sits beside a field group; page loses its corners and its inline edges because it runs to both edges of what holds it. |
| `live` | `'off' \| 'polite' \| 'assertive'` | off | Alert | Whether the text announces itself. polite writes role="status" on the content part and assertive writes role="alert"; both imply aria-live and aria-atomic, and neither is written on the box. |
| `actionsPlacement` | `'below' \| 'end'` | end for reach='page', below otherwise | Alert | Where the actions stand. below puts them on a row under the words; end puts them at the end of the words’ line, before the dismiss control, once the box is 40rem wide, and under the words below that width. |
| `hideIcon` | `boolean` | false | Alert | Draws no mark at all, for a callout that carries its own artwork in the body. |
| `icon` | `ReactNode` | — | Alert | Replaces the tone’s mark, keeping the box, the size and the place on the message’s first line. Angular projects an element carrying slAlertIcon instead. |
| `dismissible` | `boolean` | false | Alert | Renders the control that closes the message. Leave it off for a critical banner that must stay until the condition is resolved. |
| `messages` | `Partial<AlertMessages>` | — | Alert | Words laid over the language in force, key by key: what that control announces (dismiss). |
| `open` | `boolean` | — | Alert | The openness the consumer owns. Passing it puts the alert in controlled mode: the alert only requests changes and the consumer moves open. |
| `defaultOpen` | `boolean` | true | Alert | The openness an uncontrolled alert starts from, read once. A later change to it is not silently adopted. |
| `restoreFocus` | `boolean` | true | Alert | Returns the keyboard to the element it came from when the message closes with focus inside it. Nothing moves when focus was never there. |
| `render` | `(props) => ReactNode` | — | Alert, AlertContent, AlertTitle, AlertDescription, AlertActions | Substitutes the rendered element of a part, and hands it every data attribute. A title rendered as a heading is how a page puts the message in its outline. |
| `ref` | `Ref<HTMLElement>` | — | Alert | Reaches the section, which carries tabindex="-1" so focus() works. There is no imperative handle beyond it: Alert never moves focus on its own, because the APG says an alert must not affect keyboard focus. |
| `AlertDefaultsProvider` | `{ tone, variant, reach, live }` | — | a subtree | Sets all four once for every alert under it; an explicit prop on one message still wins. |
| `children` | `ReactNode` | — | AlertContent | The title and the description. Anything else placed here joins the live region, which is why the actions are a part of their own. |

## Events

| Name | Payload | When |
| --- | --- | --- |
| `onOpenChange` | `open: boolean, request: ChangeRequest<boolean>` | The dismiss control is activated. request.reason is dismiss, request.source is the click event, and request.cancel() refuses the change — the message stays open and the keyboard stays where it is. Nothing is emitted when the consumer moves open themselves. |

## Axes and defaults

| Axis | Values | Default |
| --- | --- | --- |
| `tone` | `accent`, `secondary`, `info`, `success`, `warning`, `danger` | `accent` |
| `variant` | `soft`, `outline`, `solid` | `soft` |
| `reach` | `inline`, `section`, `page` | `section` |
| `live` | `off`, `polite`, `assertive` | `off` |
| `actionsPlacement` | `below`, `end` | — |

## Rules

- The applicable pattern is the WAI-ARIA APG Alert Pattern (w3.org/WAI/ARIA/apg/patterns/alert/). It declares one role and no keyboard interaction: an alert is not a widget, so it holds no keys. Its two prose requirements — that an alert must not affect keyboard focus, and must not disappear on its own — are why Alert never moves focus and never dismisses itself.
- The box is a landmark, not a live region. MDN’s alert role reference states that the role “should only be used for text content, not interactive elements such as links or buttons”, and an alert can carry a dismiss control and actions. The root renders a section named by its own title through aria-labelledby, and the region that announces is the content part, which holds the title and the description alone.
- live defaults to off because the APG records that “screen readers do not inform users of alerts that are present on the page before page load completes”. An alert already on the page announces nothing whatever role it carries; polite and assertive are for a message that arrives while the reader is working, and both are written as a role that already implies aria-live and aria-atomic.
- Every tone with a severity carries a mark as well as a color, and secondary carries none: a neutral note has no severity to state. Under forced colors the grounds become one system color and the borders one more, so the mark, and its absence on a note, is the only thing distinguishing an error from a note — WCAG 2.2 1.4.1.
- The dismiss control is a native button with an accessible name, not a Button: its box is the glyph plus a step of air on each side, floored at --slotted-target-min, which is the WCAG 2.2 2.5.8 minimum of 24 CSS pixels; at rest it has no frame and no ground, and hover moves only the ground.
- When the message closes with focus inside it, the keyboard goes back to the element it came from. Without it, the dismiss control is hidden, focus falls to the document body, and the next Tab starts again at the top of the page.
- Closing hides rather than unmounts, so the live region is still in the document if the message comes back and data-open is a state a consumer can style. An application that must not pay for the hidden subtree renders the alert conditionally and never passes defaultOpen.
- Escape does not close the message. An alert is not a dismissable layer, and one inside a dialog would swallow the dialog’s own Escape; a message that must interrupt the reader is an alert dialog rather than an alert.

## Tokens

`--slotted-action-gap`, `--slotted-alert-actions-gap`, `--slotted-alert-border-width`, `--slotted-alert-column-gap`, `--slotted-alert-dismiss-radius`, `--slotted-alert-dismiss-size`, `--slotted-alert-font-family`, `--slotted-alert-padding-block`, `--slotted-alert-padding-inline`, `--slotted-alert-radius`, `--slotted-alert-row-gap`, `--slotted-alert-state-layer-active`, `--slotted-alert-state-layer-hover`, `--slotted-alert-text-gap`, `--slotted-alert-title-font-family`, `--slotted-alert-title-font-weight`, `--slotted-border-width-thin`, `--slotted-control-font-family`, `--slotted-control-font-size-lg`, `--slotted-control-font-size-md`, `--slotted-control-font-size-sm`, `--slotted-control-icon-size-lg`, `--slotted-control-icon-size-md`, `--slotted-control-icon-size-sm`, `--slotted-control-inner-size-lg`, `--slotted-control-inner-size-md`, `--slotted-control-inner-size-sm`, `--slotted-control-radius`, `--slotted-control-transition-duration`, `--slotted-control-transition-easing`, `--slotted-disabled-foreground`, `--slotted-duration-short`, `--slotted-easing-enter`, `--slotted-easing-exit`, `--slotted-focus-ring-color`, `--slotted-focus-ring-offset`, `--slotted-focus-ring-width`, `--slotted-font-family-heading`, `--slotted-font-family-sans`, `--slotted-font-weight-semibold`, `--slotted-line-height-md`, `--slotted-radius-md`, `--slotted-radius-sm`, `--slotted-space-2`, `--slotted-space-4`, `--slotted-space-5`, `--slotted-space-6`, `--slotted-space-7`, `--slotted-target-comfortable`, `--slotted-target-min`, `--slotted-tone-accent-border`, `--slotted-tone-accent-on-solid`, `--slotted-tone-accent-solid`, `--slotted-tone-accent-surface`, `--slotted-tone-accent-text`, `--slotted-tone-danger-border`, `--slotted-tone-danger-on-solid`, `--slotted-tone-danger-solid`, `--slotted-tone-danger-surface`, `--slotted-tone-danger-text`, `--slotted-tone-info-border`, `--slotted-tone-info-on-solid`, `--slotted-tone-info-solid`, `--slotted-tone-info-surface`, `--slotted-tone-info-text`, `--slotted-tone-secondary-border`, `--slotted-tone-secondary-on-solid`, `--slotted-tone-secondary-solid`, `--slotted-tone-secondary-surface`, `--slotted-tone-secondary-text`, `--slotted-tone-success-border`, `--slotted-tone-success-on-solid`, `--slotted-tone-success-solid`, `--slotted-tone-success-surface`, `--slotted-tone-success-text`, `--slotted-tone-warning-border`, `--slotted-tone-warning-on-solid`, `--slotted-tone-warning-solid`, `--slotted-tone-warning-surface`, `--slotted-tone-warning-text`

## Examples

See [alert.examples.md](./alert.examples.md).
