Skip to content

Alert

Pro

A message that stays until it's resolved: a form's error, a page's warning, a system notice. Error, info, success, warning and neutral, tonal or outlined. Not an M3 component (@windmorph/react-pro).

import { Alert } from '@windmorph/react-pro';

Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.

Props

By name or description, across the 16 props below

Alert 16 props

  • childrentype ReactNodeRequired

    The message.

  • titletype ReactNode

    A short summary above the message.

  • headingLeveltype 2 | 3 | 4 | 5 | 6

    Makes the title a heading of this level, when the alert heads a section. Left out, the title is a paragraph.

  • severitytype "error" | "info" | "success" | "warning" | "neutral"default "info"

    What kind of message it is; picks the colours and the icon. error is read at once (role="alert"); the others are a polite status, so pass error for a failure the person must act on.

  • varianttype "tonal" | "outlined"default "tonal"

    tonal (a container colour) or outlined (quieter).

  • icontype ReactNode

    Replaces the severity's icon; null shows none.

  • actionstype ReactNode

    Up to two Buttons, text or tonal.

  • opentype booleandefault true

    Whether it's shown. Set it to false (rather than unmounting the alert) to let it leave: it fades out as its height folds, then unmounts its content and calls onClosed.

  • autoFocustype booleandefault false

    Moves focus to the alert when it appears, for an error that blocks a form. A keyboard user sees the M3 focus indicator on it.

  • reftype Ref<HTMLDivElement>

    The alert itself (the live region).

Events

  • onClosetype (() => void)

    Adds a close button; without it the alert can't be dismissed. Focus leaves the alert before this is called (back to where it was before autoFocus, else the next control), so hiding the alert here never drops focus to the page.

  • onClosedtype (() => void)

    After it has left (open false) and its content is gone.

Text

  • labelstype Partial<AlertLabels>

    Its words, for translation. A LabelsProvider sets them for the whole app.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

Spec status

Not part of Material Design 3: a Windmorph Pro component, built on M3's colour roles, type scale, shapes and motion. Its variants and configurations each link to a live example.

M3 Expressive specs

Shape
rounded-corner-medium
Variants
tonal, outlined

Theming & tokens

Tonal alerts use the severity's container and on-container roles; outlined ones have no fill and on-surface text, with the border and icon in the severity's colour. A test keeps the text at 4.5:1 in every theme, mode and contrast level. Set the tokens below on an alert or an ancestor (the root carries data-tokens="wm-alert", with data-severity and data-variant picking each one's default), and style the parts with classNames (root, icon, title, message, actions, close). In forced colours every alert keeps a border.

Alert tokens
VariableDefaultPaints
--wm-alert-containervar(--_wm-alert-severity-container)Varies with variant.The background: the severity's container role (tonal) or transparent (outlined).
--wm-alert-contentvar(--_wm-alert-severity-content)Varies with variant.The title, message and close button: the severity's on-container role (tonal) or on-surface (outlined).
--wm-alert-outlinetransparentVaries with variant.The 1px border: transparent (tonal) or the severity's strong role (outlined).
--wm-alert-iconvar(--_wm-alert-severity-icon)Varies with variant.The severity's icon: the content colour (tonal) or the severity's strong role (outlined).
--wm-alert-cornervar(--md-sys-shape-corner-medium)The corners.