Snackbar API
Demos
For examples and details on the usage of this React component, visit the component demo pages:
Import
import Snackbar from '@mui/material/Snackbar';
// or
import { Snackbar } from '@mui/material';
Props of the native component are also available.
Name | Type | Default | Description |
---|---|---|---|
action | node | The action to display. It renders after the message, at the end of the snackbar. | |
anchorOrigin | { horizontal: 'center' | 'left' | 'right', vertical: 'bottom' | 'top' } | { vertical: 'bottom', horizontal: 'left' } | The anchor of the |
autoHideDuration | number | null | The number of milliseconds to wait before automatically calling the |
children | element | Replace the | |
classes | object | Override or extend the styles applied to the component. See CSS API below for more details. | |
ClickAwayListenerProps | object | Props applied to the | |
ContentProps | object | Props applied to the | |
disableWindowBlurListener | bool | false | If |
key | any | When displaying multiple consecutive snackbars using a single parent-rendered | |
message | node | The message to display. | |
onClose | func | Callback fired when the component requests to be closed. Typically Signature: function(event: React.SyntheticEvent
| |
open | bool | If | |
resumeHideDuration | number | The number of milliseconds to wait before dismissing after user interaction. If | |
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. | |
TransitionComponent | elementType | Grow | The component used for the transition. Follow this guide to learn more about the requirements for this component. |
transitionDuration | number | { appear?: number, enter?: number, exit?: number } | { enter: theme.transitions.duration.enteringScreen, exit: theme.transitions.duration.leavingScreen, } | The duration for the transition, in milliseconds. You may specify a single timeout for all transitions, or individually with an object. |
TransitionProps | object | {} | Props applied to the transition element. By default, the element is based on this |
ref
is forwarded to the root element.Theme default props
You can use MuiSnackbar
to change the default props of this component with the theme.
The following class names are useful for styling with CSS (the state classes are marked).
To learn more, visit the component customization page.
Global class | Rule name | Description |
---|---|---|
.MuiSnackbar-root | root | Styles applied to the root element. |
.MuiSnackbar-anchorOriginTopCenter | anchorOriginTopCenter | Styles applied to the root element if anchorOrigin={{ 'top', 'center' }} . |
.MuiSnackbar-anchorOriginBottomCenter | anchorOriginBottomCenter | Styles applied to the root element if anchorOrigin={{ 'bottom', 'center' }} . |
.MuiSnackbar-anchorOriginTopRight | anchorOriginTopRight | Styles applied to the root element if anchorOrigin={{ 'top', 'right' }} . |
.MuiSnackbar-anchorOriginBottomRight | anchorOriginBottomRight | Styles applied to the root element if anchorOrigin={{ 'bottom', 'right' }} . |
.MuiSnackbar-anchorOriginTopLeft | anchorOriginTopLeft | Styles applied to the root element if anchorOrigin={{ 'top', 'left' }} . |
.MuiSnackbar-anchorOriginBottomLeft | anchorOriginBottomLeft | Styles applied to the root element if anchorOrigin={{ 'bottom', 'left' }} . |
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.