0 Tk

alert

Import

import Alert from '@mui/material/Alert';
// or
import { Alert } from '@mui/material';

Learn about the difference by reading this guide on minimizing bundle size.

Props of the Paper component are also available.

Name Type Default Description
action node - The action to display. It renders after the message, at the end of the alert.
children node - The content of the component.
classes object - Override or extend the styles applied to the component. See CSS classes API below for more details.
closeText string ‘Close’ Override the default label for the close popup icon button. For localization purposes, you can use the provided translations.
color ‘error’ | ‘info’ | ‘success’ | ‘warning’ | string - The color of the component. Unless provided, the value is taken from the severity prop. It supports both default and custom theme colors, which can be added as shown in the palette customization guide.
components { CloseButton?: elementType, CloseIcon?: elementType } {} The components used for each slot inside.
componentsProps { closeButton?: object, closeIcon?: object } {} The extra props for the slot components. You can override the existing props or add new ones.
icon node - Override the icon displayed before the children. Unless provided, the icon is mapped to the value of the severity prop. Set to false to remove the icon.
iconMapping { error?: node, info?: node, success?: node, warning?: node } - The component maps the severity prop to a range of different icons, for instance success to <SuccessOutlined>. If you wish to change this mapping, you can provide your own. Alternatively, you can use the icon prop to override the icon displayed.
onClose func - Callback fired when the component requests to be closed. When provided and no action prop is set, a close icon button is displayed that triggers the callback when clicked. Signature: function(event: React.SyntheticEvent) => void
role string ‘alert’ The ARIA role attribute of the element.
severity ‘error’ | ‘info’ | ‘success’ | ‘warning’ | string ‘success’ The severity of the alert. This defines the color and icon used.
slotProps { closeButton?: func | object, closeIcon?: func | object } {} The props used for each slot inside.
slots { closeButton?: elementType, closeIcon?: elementType } {} The components used for each slot inside.
sx Array<func | object | bool> | func | object - The system prop that allows defining system overrides as well as additional CSS styles. See the sx page for more details.
variant ‘filled’ | ‘outlined’ | ‘standard’ | string ‘standard’ The variant to use.

The ref is forwarded to the root element.

Inheritance

While not explicitly documented above, the props of the Paper component are also available in Alert. You can take advantage of this to target nested components.

Theme default props

You can use MuiAlert to change the default props of this component with the theme.

Slot name Class name Default component Description
closeButton - IconButton The component that renders the close button.
closeIcon - svg The component that renders the close icon.

These class names are useful for styling with CSS. They are applied to the component’s slots when specific states are triggered.

Class name Rule name Description
.MuiAlert-action action Styles applied to the action wrapper element if action is provided.
.MuiAlert-colorError colorError Styles applied to the root element if color="error".
.MuiAlert-colorInfo colorInfo Styles applied to the root element if color="info".
.MuiAlert-colorSuccess colorSuccess Styles applied to the root element if color="success".
.MuiAlert-colorWarning colorWarning Styles applied to the root element if color="warning".
.MuiAlert-filled filled Styles applied to the root element if variant="filled".
.MuiAlert-filledError filledError Styles applied to the root element if variant="filled" and color="error".
.MuiAlert-filledInfo filledInfo Styles applied to the root element if variant="filled" and color="info".
.MuiAlert-filledSuccess filledSuccess Styles applied to the root element if variant="filled" and color="success".
.MuiAlert-filledWarning filledWarning Styles applied to the root element if variant="filled" and color="warning"
.MuiAlert-icon icon Styles applied to the icon wrapper element.
.MuiAlert-message message Styles applied to the message wrapper element.
.MuiAlert-outlined outlined Styles applied to the root element if variant="outlined".
.MuiAlert-outlinedError outlinedError Styles applied to the root element if variant="outlined" and color="error".
.MuiAlert-outlinedInfo outlinedInfo Styles applied to the root element if variant="outlined" and color="info".
.MuiAlert-outlinedSuccess outlinedSuccess Styles applied to the root element if variant="outlined" and color="success".
.MuiAlert-outlinedWarning outlinedWarning Styles applied to the root element if variant="outlined" and color="warning".
.MuiAlert-root root Styles applied to the root element.
.MuiAlert-standard standard Styles applied to the root element if variant="standard".
.MuiAlert-standardError standardError Styles applied to the root element if variant="standard" and color="error".
.MuiAlert-standardInfo standardInfo Styles applied to the root element if variant="standard" and color="info".
.MuiAlert-standardSuccess standardSuccess Styles applied to the root element if variant="standard" and color="success".
.MuiAlert-standardWarning standardWarning Styles applied to the root element if variant="standard" and color="warning".

You can override the style of the component using one of these customization options:

Source code

If you did not find the information in this page, consider having a look at the implementation of the component for more detail.