logo

SINGULARITY

DOCS

PurchaseReturn to the Dashboard
Reference

Alert

Alerts convey concise messages to users without disrupting their interaction with the application.

Introduction

Alerts provide users with brief, potentially time-sensitive information in a non-intrusive way.
The Material UI Alert component offers various props to customize its appearance, delivering immediate visual cues about its content.
This component is no longer included in the Material Design guidelines, but Material UI will continue to support it.

Usage

A defining characteristic of the alert pattern is that it does not interrupt the user's experience. Alerts should not be confused with alert dialogs (ARIA), which are designed to interrupt the user to prompt a response. For such behavior, use the Material UI Dialog component.

Basics

import Alert from '@mui/material/Alert';
The Alert component surrounds its content and expands to fill its parent container.

Severity

The severity prop supports four values—success (default), info, warning, and error—each with corresponding icons and colors:

Variants

The Alert component provides two alternative styles—filled and outlined—configurable via the variant prop.

Filled

Outlined

:::warning When using an outlined Alert with the Snackbar component, background content may be visible through the Alert by default. To prevent this, add bgcolor: 'background.paper' to the sx prop on the Alert component:
<Alert sx={{ bgcolor: 'background.paper' }} />
Refer to the Snackbar—customization documentation for an example of combining these components. :::

Color

Use the color prop to override the default color for a specified severity, such as applying warning colors to a success Alert:

Actions

Add an action to an Alert using the action prop, allowing you to place any element—such as an HTML tag, SVG icon, or Material UI Button—after the Alert's message, aligned to the right.
If you provide an onClose callback without setting the action prop, the Alert will display a default close icon (âś•).

Icons

Override an Alert's icon using the icon prop, which accepts an HTML element, SVG icon, or React component. Set the prop to false to remove the icon entirely.
To override all icons for a given severity, use the iconMapping prop instead. This can be defined globally by customizing the app's theme. See Theme components—Default props for details.

Customization

Titles

To include a title in an Alert, import the AlertTitle component:
import AlertTitle from '@mui/material/AlertTitle';
Nest the AlertTitle component above the message in your Alert for a well-styled and properly aligned title, as demonstrated below:

Transitions

Enhance an Alert's entrance and exit with Transition components such as Collapse.

Accessibility

To ensure your Alert is accessible, consider the following:
  • Alerts are designed to avoid interfering with the app's usability, so the Alert component should never affect keyboard focus.
  • If an alert includes an action, that action must have a tabindex of 0 to ensure accessibility for keyboard-only users.
  • Critical alerts should not disappear automatically, as timed interactions can hinder accessibility for users who need more time to read or locate the alert.
  • Frequent alerts can impair the usability of your application.
  • Dynamically rendered alerts are announced by screen readers, whereas alerts present on page load are not announced.
  • Color alone should not convey meaning for users relying on assistive technology. Ensure that information conveyed through color is also expressed through text or hidden text accessible to screen readers.

Anatomy

The Alert component consists of a root Paper component (rendered as a <div>) containing an icon, a message, and an optional action:
<div className="MuiPaper-root MuiAlert-root" role="alert">
  <div className="MuiAlert-icon">
    
  </div>
  <div className="MuiAlert-message">This is how an Alert renders in the DOM.</div>
  <div className="MuiAlert-action">
    
  </div>
</div>