Alert API
Demos
For examples and details on the usage of this React component, visit the component demo pages:
Import
import Alert from '@mui/material/Alert';
// or
import { Alert } from '@mui/material';
Props
Props of the Paper component are also available.
Override the default label for the close popup icon button.
For localization purposes, you can use the provided translations.
Type:
string
Default:
'Close'
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.
Type:
'error' | 'info' | 'success' | 'warning' | string
The components used for each slot inside.
This prop is an alias for the slots
prop. It's recommended to use the slots
prop instead.
Type:
{ CloseButton?: elementType, CloseIcon?: elementType }
Default:
{}
The extra props for the slot components. You can override the existing props or add new ones.
This prop is an alias for the slotProps
prop. It's recommended to use the slotProps
prop instead, as componentsProps
will be deprecated in the future.
Type:
{ closeButton?: object, closeIcon?: object }
Default:
{}
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
.
Type:
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.
Type:
{ error?: node, info?: node, success?: node, warning?: node }
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.
Type:
func
Signature:
function(event: React.SyntheticEvent) => void
event
The event source of the callback.
The severity of the alert. This defines the color and icon used.
Type:
'error' | 'info' | 'success' | 'warning'
Default:
'success'
The extra props for the slot components. You can override the existing props or add new ones.
This prop is an alias for the componentsProps
prop, which will be deprecated in the future.
Type:
{ closeButton?: object, closeIcon?: object }
Default:
{}
The components used for each slot inside.
This prop is an alias for the components
prop, which will be deprecated in the future.
Type:
{ closeButton?: elementType, closeIcon?: elementType }
Default:
{}
The system prop that allows defining system overrides as well as additional CSS styles.
Type:
Array<func | object | bool> | func | object
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 useMuiAlert
to change the default props of this component with the theme.CSS
The following class names are useful for styling with CSS (the state classes are marked).
To learn more, visit the component customization page.
Styles applied to the root element if variant="standard"
and color="success"
.
Styles applied to the root element if variant="standard"
and color="info"
.
Styles applied to the root element if variant="standard"
and color="warning"
.
Styles applied to the root element if variant="standard"
and color="error"
.
Styles applied to the root element if variant="outlined"
and color="success"
.
Styles applied to the root element if variant="outlined"
and color="info"
.
Styles applied to the root element if variant="outlined"
and color="warning"
.
Styles applied to the root element if variant="outlined"
and color="error"
.
Styles applied to the root element if variant="filled"
and color="success"
.
Styles applied to the root element if variant="filled"
and color="info"
.
Styles applied to the root element if variant="filled"
and color="warning"
.
Styles applied to the root element if variant="filled"
and color="error"
.
You can override the style of the component using one of these customization options:
- With a global class name.
- With a rule name as part of the component's
styleOverrides
property in a custom theme.