Alert
An in-page status message with a type icon, optional actions and close button.
Usage guidelines
- Use
Alertfor a status that stays relevant while the user works on the surrounding content, such as an archived range, a conflicting edit or a form rejection that belongs to no field. Feedback on an action that is over once it is seen is aToast, and a decision the user must answer before continuing is anAlertDialog. typesets the icon, the halo and the default role. Anerroralert usesrole="alert"and interrupts assistive technology; the other types userole="status"and wait for a pause.- Pass
rolewhen the default does not fit. An error that is already present when the page loads, rather than the result of something the user did, takes a non-live role such asnoteso it does not interrupt. - The icon comes from
typeand cannot be replaced. A banner that needs a product or business icon is not anAlert. - Every alert has an
AlertTitle. A one-sentence message uses the title alone; addAlertDescriptionfor detail andAlertActionsfor buttons below the text, using smallButtons. AlertCloseis a stateless button with a requiredaria-label. The caller owns whether the alert is visible, whether the dismissal persists and where focus goes, because the focused close button leaves the page with the alert.
Anatomy
Alert renders the icon and halo for its type and lays out the content beside it. AlertClose sits at the inline end and the content reserves space for it.
Examples
Types
info, success, warning and error set the icon, the halo and the default role. These alerts are present when the page loads, so the error alert passes role="note".
Actions
AlertActions places buttons below the title and description.
Dismissible
AlertClose only reports the click. The caller removes the alert, moves focus to the button that replaces it and decides when the alert comes back.
API reference
Alert
An in-page status message with a semantic icon and background halo. Renders a <div> element.
Sets role="alert" when type="error" and role="status" otherwise; pass role explicitly when an error is already present on load.
| Prop | Type | Default | Details |
|---|---|---|---|
type required | 'error' | 'info' | 'success' | 'warning' | No default | |
| Attribute | Description |
|---|---|
data-type | Values: The alert type, which sets the icon, the halo and the default role. |
AlertActions
Accepts the props of the element it renders.
AlertClose
A stateless close button for dismissing an alert; callers own visibility state. Renders a <button> element.
| Prop | Type | Default | Details |
|---|---|---|---|
aria-label required | string | No default | |
className | string | ((state: ButtonState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, ButtonState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: ButtonState) => React.CSSProperties | undefined) | No default | |
nativeButton | boolean | true | |
focusableWhenDisabled | boolean | false | |
| Attribute | Description |
|---|---|
data-disabled | Present when the button is disabled. |
AlertDescription
| Prop | Type | Default | Details |
|---|---|---|---|
render | ComponentRenderFn<HTMLProps, {}> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
AlertTitle
| Prop | Type | Default | Details |
|---|---|---|---|
render | ComponentRenderFn<HTMLProps, {}> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |