Alert
ProA 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.
Purpose
An alert is a message that stays until it's resolved: a form's error, a page's warning, a system notice. It is not an M3 component: M3 Expressive has no persistent message, so it comes from @windmorph/react-pro, built from M3's colour roles, type and shape scales, Button and IconButton.
- Brief feedback that goes away by itself: a Snackbar.
- A problem with one field: the field's error text.
- A region with no content, or that couldn't load: an Empty state.
- A decision that blocks the page (what some platforms call an alert): a Dialog with
role="alertdialog".
Behaviour
- It is a live region (
alertfor theerrorseverity,statusfor the others; the default isinfo) that goes into the page first and shows its content a moment later, so screen readers announce it even when it mounts with its message. One in the server's HTML shows at once. - It fades in on the default effects spring, under reduced motion too.
- To let it leave, set
open={false}instead of unmounting it: it fades out as its height folds (on the effects easing, so it never bounces), then unmounts its content and callsonClosed. Under reduced motion it only fades, keeping its height until it has gone. onCloseadds a close button. BeforeonCloseruns, focus moves back to where it was beforeautoFocus, or on to the next control, so hiding the alert never drops focus to the page.autoFocusmoves focus to the alert as it appears, for an error that blocks a form, and scrolls it into view no further than needed. A keyboard user sees the M3 focus indicator on it.- Up to two actions move beside the text once the alert is at least 480px wide. Text buttons in a tonal alert take its content colour; its close button keeps its size at every density.
When not to use
For brief feedback use a Snackbar; for one field, its error text; for a decision that blocks the page, a Dialog.
See also
- Snackbar: A brief message with an optional action and dismiss, queued through a host.
- Dialog: A modal surface for a focused task or a decision, with a title, content and actions, or full screen on compact windows.
- Empty state: Fills a region with nothing to show: no posts yet, no results, coming soon, or couldn't load with a retry. Not an M3 component (@windmorph/react-pro).