Snackbar API
API reference docs for the React Snackbar component. Learn about the props, CSS, and other APIs of this exported module.
Demos
Import
import Snackbar from '@mui/joy/Snackbar';
// or
import { Snackbar } from '@mui/joy';
Learn about the difference by reading this guide on minimizing bundle size.
Name | Type | Default | Description |
---|---|---|---|
open* | bool | - | If |
anchorOrigin | { horizontal: 'center' | 'left' | 'right', vertical: 'bottom' | 'top' } | { vertical: 'bottom', horizontal: 'right' } | The anchor of the |
animationDuration | number | 300 | The duration of the animation in milliseconds. This value is used to control the length of time it takes for an animation to complete one cycle. It is also utilized for delaying the unmount of the component. Provide this value if you have your own animation so that we can precisely time the component's unmount to match your custom animation. |
autoHideDuration | number | null | The number of milliseconds to wait before automatically calling the |
color | 'danger' | 'neutral' | 'primary' | 'success' | 'warning' | 'neutral' | The color of the component. It supports those theme colors that make sense for this component. To learn how to add your own colors, check out Themed components—Extend colors. |
component | elementType | - | The component used for the root node. Either a string to use a HTML element or a component. |
disableWindowBlurListener | bool | false | If |
endDecorator | node | - | Element placed after the children. |
invertedColors | bool | false | If |
key | any | - | When displaying multiple consecutive snackbars using a single parent-rendered |
onClose | func | - | Callback fired when the component requests to be closed. Typically Signature: function(event: React.SyntheticEvent
|
onUnmount | func | - | A callback fired when the component is about to be unmounted. |
resumeHideDuration | number | - | The number of milliseconds to wait before dismissing after user interaction. If |
size | 'sm' | 'md' | 'lg' | 'md' | The size of the component. To learn how to add custom sizes to the component, check out Themed components—Extend sizes. |
slotProps | { clickAway?: func | { children: element, disableReactTree?: bool, mouseEvent?: 'onClick' | 'onMouseDown' | 'onMouseUp' | 'onPointerDown' | 'onPointerUp' | false, onClickAway: func, touchEvent?: 'onTouchEnd' | 'onTouchStart' | false }, endDecorator?: func | object, root?: func | object, startDecorator?: func | object } | {} | The props used for each slot inside. |
slots | { clickAway?: elementType, endDecorator?: elementType, root?: elementType, startDecorator?: elementType } | {} | The components used for each slot inside. See Slots API below for more details. |
startDecorator | node | - | Element placed before the children. |
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 | 'outlined' | 'plain' | 'soft' | 'solid' | 'outlined' | The global variant to use. To learn how to add your own variants, check out Themed components—Extend variants. |
ref
is forwarded to the root element.Theme default props
You can use JoySnackbar
to change the default props of this component with the theme.
To learn how to customize the slot, check out the Overriding component structure guide.
Slot name | Class name | Default component | Description |
---|---|---|---|
root | .MuiSnackbar-root | 'div' | The component that renders the root. |
startDecorator | .MuiSnackbar-startDecorator | 'span' | The component that renders the start decorator. |
endDecorator | .MuiSnackbar-endDecorator | 'span' | The component that renders the end decorator. |
clickAway | ClickAwayListener | The component that renders the click away. |
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 |
---|---|---|
.MuiSnackbar-anchorOriginBottomCenter | anchorOriginBottomCenter | Styles applied to the root element if anchorOrigin={{ 'bottom', 'center' }} . |
.MuiSnackbar-anchorOriginBottomLeft | anchorOriginBottomLeft | Styles applied to the root element if anchorOrigin={{ 'bottom', 'left' }} . |
.MuiSnackbar-anchorOriginBottomRight | anchorOriginBottomRight | Styles applied to the root element if anchorOrigin={{ 'bottom', 'right' }} . |
.MuiSnackbar-anchorOriginTopCenter | anchorOriginTopCenter | Styles applied to the root element if anchorOrigin={{ 'top', 'center' }} . |
.MuiSnackbar-anchorOriginTopLeft | anchorOriginTopLeft | Styles applied to the root element if anchorOrigin={{ 'top', 'left' }} . |
.MuiSnackbar-anchorOriginTopRight | anchorOriginTopRight | Styles applied to the root element if anchorOrigin={{ 'top', 'right' }} . |
.MuiSnackbar-colorDanger | colorDanger | Class name applied to the root element if color="danger" . |
.MuiSnackbar-colorNeutral | colorNeutral | Class name applied to the root element if color="neutral" . |
.MuiSnackbar-colorPrimary | colorPrimary | Class name applied to the root element if color="primary" . |
.MuiSnackbar-colorSuccess | colorSuccess | Class name applied to the root element if color="success" . |
.MuiSnackbar-colorWarning | colorWarning | Class name applied to the root element if color="warning" . |
.MuiSnackbar-sizeLg | sizeLg | Class name applied to the root element if size="lg" . |
.MuiSnackbar-sizeMd | sizeMd | Class name applied to the root element if size="md" . |
.MuiSnackbar-sizeSm | sizeSm | Class name applied to the root element if size="sm" . |
.MuiSnackbar-variantOutlined | variantOutlined | Class name applied to the root element if variant="outlined" . |
.MuiSnackbar-variantPlain | variantPlain | Class name applied to the root element if variant="plain" . |
.MuiSnackbar-variantSoft | variantSoft | Class name applied to the root element if variant="soft" . |
.MuiSnackbar-variantSolid | variantSolid | Class name applied to the root element if variant="solid" . |
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.