Skip to content
+

Snackbar

The Snackbar component informs users that an action has been or will be performed by the app.

Snackbar API

Import

import { Snackbar } from '@mui/base/Snackbar';
// or
import { Snackbar } from '@mui/base';
Learn about the difference by reading this guide on minimizing bundle size.

Props

Props of the native component are also available.

autoHideDuration

The number of milliseconds to wait before automatically calling the onClose function. onClose should then set the state of the open prop to hide the Snackbar. This behavior is disabled by default with the null value.

Type:number

Default:null


disableWindowBlurListener

If true, the autoHideDuration timer will expire even if the window is not focused.

Type:bool

Default:false


exited

The prop used to handle exited transition and unmount the component.

Type:bool

Default:true


onClose

Callback fired when the component requests to be closed. Typically onClose is used to set state in the parent component, which is used to control the Snackbar open prop. The reason parameter can optionally be used to control the response to onClose, for example ignoring clickaway.

Type:func

Signature:
function(event: React.SyntheticEvent | Event, reason: string) => void
  • event The event source of the callback.
  • reason Can be: "timeout" (autoHideDuration expired), "clickaway", or "escapeKeyDown".

open

If true, the component is shown.

Type:bool


resumeHideDuration

The number of milliseconds to wait before dismissing after user interaction. If autoHideDuration prop isn't specified, it does nothing. If autoHideDuration prop is specified but resumeHideDuration isn't, we default to autoHideDuration / 2 ms.

Type:number


slotProps

The props used for each slot inside the Snackbar.

Type:{ clickAwayListener?: func
| { children: element, disableReactTree?: bool, mouseEvent?: 'onClick'
| 'onMouseDown'
| 'onMouseUp'
| 'onPointerDown'
| 'onPointerUp'
| false, onClickAway?: func, touchEvent?: 'onTouchEnd'
| 'onTouchStart'
| false }, root?: func
| object }

Default:{}


slots

The components used for each slot inside the Snackbar. Either a string to use a HTML element or a component.

See Slots API below for more details.

Type:{ root?: elementType }

Default:{}



The ref is forwarded to the root element.

Slots

To learn how to customize the slot, check out the Overriding component structure guide.

root

The component that renders the root.

Class name: .base-Snackbar-root

Default component: 'div'