Alert

Show a message that stays in the page, with an optional title, icon and close button.

General

The basic Alert usage. Errors and warnings are announced right away by a screen reader, the other types wait for a pause.

Variants

Use filled, light or subtle to change how much the color takes over.

Dismissible

onClose shows a close button. Hide the alert in your state, and bring it back when the cause returns.

With an icon and an action

Put an icon before the text, and any element, such as a button, after it.

APIs

Alert.Props

AttributeDescriptionTypeAccepted valuesDefault
typecolor of the alert'default' | 'primary' | 'secondary' | 'success' | 'warning' | 'error' | 'info'-default
titlebold first lineReactNode--
iconelement before the textReactNode--
filledsolid colorboolean-false
lighttinted backgroundboolean-false
subtletext only, no borderboolean-false
onCloseshows a close button and calls it on click() => void--
closeLabelaccessible name of the close buttonstring-Close
roledefaults to alert for errors and warnings, status otherwisestring--
...native propsHTMLAttributes--

Accessibility

  • • error and warning use role="alert", so a screen reader announces them as soon as they appear. The other types use role="status", which waits until the reader is done with what it was saying.
  • • The icon is hidden from screen readers. The title and the text carry the message, so do not rely on the color of the type alone.
  • • The close button is named by closeLabel, Close by default. Set it in the language of your page.
Edit this page on GitHub