Alert
Alerts provide contextual feedback messages for typical user actions with a handful of available and flexible alert messages.Overview
The Alert component can be used to display success, informational, warning, or error messages to users. It extends the Paper component and includes built-in icon mapping for each severity level.Basic Usage
With Actions
Alerts can include action buttons or close icons:Props
Main Props
| Prop | Type | Default | Description |
|---|---|---|---|
severity | 'success' | 'info' | 'warning' | 'error' | 'success' | The severity of the alert. Defines the color and icon used. |
variant | 'standard' | 'filled' | 'outlined' | 'standard' | The variant to use. |
color | AlertColor | - | The color of the component. Unless provided, taken from severity. |
icon | ReactNode | - | Override the icon displayed before the children. Set to false to remove the icon. |
action | ReactNode | - | The action to display at the end of the alert. |
onClose | (event: SyntheticEvent) => void | - | Callback fired when close is requested. When provided with no action prop, a close icon button is displayed. |
closeText | string | 'Close' | Override the default label for the close popup icon button. |
iconMapping | Partial<Record<AlertColor, ReactNode>> | - | Custom mapping of severity to icon. |
role | string | 'alert' | The ARIA role attribute of the element. |
sx | SxProps<Theme> | - | System prop for defining CSS overrides. |
Slot Props
The Alert component supports slot-based customization:slots.root- The root Paper componentslots.icon- The icon containerslots.message- The message containerslots.action- The action containerslots.closeButton- The close button (IconButton)slots.closeIcon- The close icon (SvgIcon)
slotProps to pass props to each slot:
CSS Classes
The component has the following CSS classes available:.MuiAlert-root- Root element.MuiAlert-icon- Icon wrapper.MuiAlert-message- Message wrapper.MuiAlert-action- Action wrapper.MuiAlert-standard- Standard variant.MuiAlert-filled- Filled variant.MuiAlert-outlined- Outlined variant.MuiAlert-standardSuccess- Standard success.MuiAlert-standardInfo- Standard info.MuiAlert-standardWarning- Standard warning.MuiAlert-standardError- Standard error
Inheritance
Alert inherits from the Paper component.API Reference
For complete API documentation, see:Source Location
~/workspace/source/packages/mui-material/src/Alert/Alert.d.ts:211