跳转到内容

SnackbarUnstyled API

想要学习更多组件属性和 CSS API,可以查阅 React SnackbarUnstyled 组件的 API 文档。

导入

import SnackbarUnstyled from '@mui/base/SnackbarUnstyled';
// 或
import { SnackbarUnstyled } from '@mui/base';
你可以阅读这个关于最小化捆绑包的指南以了解以上二者的差异。

属性

原生(Native) 组件的属性也是可用的。

名称类型默认值描述
autoHideDurationnumbernull
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.
componentelementType
The component used for the Root slot. Either a string to use a HTML element or a component. This is equivalent to components.Root. If both are provided, the component is used.
disableWindowBlurListenerboolfalse
If true, the autoHideDuration timer will expire even if the window is not focused.
exitedbooltrue
onClosefunc
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.

Signature:
function(event: React.SyntheticEvent<any> | Event, reason: string) => void
event: The event source of the callback.
reason: Can be: "timeout" (autoHideDuration expired), "clickaway", or "escapeKeyDown".
openboolfalse
If true, the component is shown.
resumeHideDurationnumber
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.
slotProps{ clickAwayListener?: func
| { children: element, disableReactTree?: bool, mouseEvent?: 'onClick'
| 'onMouseDown'
| 'onMouseUp'
| 'onPointerDown'
| 'onPointerUp'
| false, onClickAway?: func, touchEvent?: 'onTouchEnd'
| 'onTouchStart'
| false }, root?: func
| object }
{}
slots{ root?: elementType }{}

ref 则会被传递到根元素中。

演示项目