Snackbar API
Importação
import Snackbar from '@mui/material/Snackbar';
// ou
import { Snackbar } from '@mui/material';Nome do componente
The nameMuiSnackbar can be used when providing default props or style overrides in the theme.Propriedades
Propriedades do componente nativo também estão disponíveis.
| Nome | Tipo | Padrão | Descrição | 
|---|---|---|---|
| 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  Snackbar. On smaller screens, the component grows to occupy all the available width, the horizontal alignment is ignored. | 
| autoHideDuration | number | null | The number of milliseconds to wait before automatically calling the  onClosefunction.onCloseshould then set the state of theopenprop to hide the Snackbar. This behavior is disabled by default with thenullvalue. | 
| children | element | Replace the  SnackbarContentcomponent. | |
| classes | object | Sobrescreve ou extende os estilos aplicados para o componente. Veja a API CSS abaixo para maiores detalhes. | |
| ClickAwayListenerProps | object | Props applied to the  ClickAwayListenerelement. | |
| ContentProps | object | Props applied to the  SnackbarContentelement. | |
| disableWindowBlurListener | bool | false | If  true, theautoHideDurationtimer will expire even if the window is not focused. | 
| key | any | When displaying multiple consecutive Snackbars from a parent rendering a single <Snackbar/>, add the key prop to ensure independent treatment of each message. e.g. <Snackbar key={message} />, otherwise, the message may update-in-place and features such as autoHideDuration may be canceled. | |
| message | node | The message to display. | |
| onClose | func | Callback fired when the component requests to be closed. Typically  onCloseis used to set state in the parent component, which is used to control theSnackbaropenprop. Thereasonparameter can optionally be used to control the response toonClose, for example ignoringclickaway.Signature: function(event: React.SyntheticEvent<any> | Event, reason: string) => voidevent: The event source of the callback. reason: Can be: "timeout"(autoHideDurationexpired),"clickaway", or"escapeKeyDown". | |
| open | bool | false | Control the popup` open state. | 
| resumeHideDuration | number | The number of milliseconds to wait before dismissing after user interaction. If  autoHideDurationprop isn't specified, it does nothing. IfautoHideDurationprop is specified butresumeHideDurationisn't, we default toautoHideDuration / 2ms. | |
| 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  Transitioncomponent. | 
O
ref é encaminhado para o elemento raiz.CSS
| Nome da regra | Classe global | Descrição | 
|---|---|---|
| root | .MuiSnackbar-root | Estilos aplicados ao elemento raiz. | 
| anchorOriginTopCenter | .MuiSnackbar-anchorOriginTopCenter | Estilos aplicados para o elemento raiz se anchorOrigin={{ 'top', 'center' }}. | 
| anchorOriginBottomCenter | .MuiSnackbar-anchorOriginBottomCenter | Estilos aplicados para o elemento raiz se anchorOrigin={{ 'bottom', 'center' }}. | 
| anchorOriginTopRight | .MuiSnackbar-anchorOriginTopRight | Estilos aplicados para o elemento raiz se anchorOrigin={{ 'top', 'right' }}. | 
| anchorOriginBottomRight | .MuiSnackbar-anchorOriginBottomRight | Estilos aplicados para o elemento raiz se anchorOrigin={{ 'bottom', 'right' }}. | 
| anchorOriginTopLeft | .MuiSnackbar-anchorOriginTopLeft | Estilos aplicados para o elemento raiz se anchorOrigin={{ 'top', 'left' }}. | 
| anchorOriginBottomLeft | .MuiSnackbar-anchorOriginBottomLeft | Estilos aplicados para o elemento raiz se anchorOrigin={{ 'bottom', 'left' }}. | 
Você pode sobrescrever o estilo do componente usando uma dessas opções de customização:
- With a global class name.
- With a rule name as part of the component's styleOverridesproperty in a custom theme.