A Snackbar displays a succinct message that is cleared out after a small delay.
It can also offer the user options, like viewing a published post. But these options should also be available elsewhere in the UI.
import { Snackbar } from '@wordpress/components';
LinksPermalink to this section
PropsPermalink to this section
| Name | Default | Description |
|---|---|---|
children Required |
The displayed message of a notice. Also used as the spoken message for
assistive technology, unless | |
className |
A CSS | |
spokenMessage | children |
Used to provide a custom spoken message in place of the |
onRemove | noop |
Function called when dismissing the notice |
politeness | 'polite' |
A politeness level for the notice’s spoken message. Should be provided as
one of the valid options for an A value of Note that this value should be considered a suggestion; assistive technologies may override it based on internal heuristics. |
onDismiss | noop |
A deprecated alternative to |
icon | null |
The icon to render in the snackbar. |
explicitDismiss | false |
Whether to require user action to dismiss the snackbar. By default, this is dismissed on a timeout, without user interaction. |
listRef |
A ref to the list that contains the snackbar. | |
actions | [] |
An array of action objects. Each member object should contain:
The default appearance of an action button is inferred based on whether
|
as |
The HTML element or React component to render the component as. |
ExamplesPermalink to this section
DefaultPermalink to this section
const Default = ( {
children,
...props
} ) => {
return <Snackbar { ...props }>{ children }</Snackbar>;
};
With ActionsPermalink to this section
const WithActions = ( {
children,
...props
} ) => {
return <Snackbar { ...props }>{ children }</Snackbar>;
};
With IconPermalink to this section
const WithIcon = ( {
children,
...props
} ) => {
return <Snackbar { ...props }>{ children }</Snackbar>;
};
With Explicit DismissPermalink to this section
const WithExplicitDismiss = ( {
children,
...props
} ) => {
return <Snackbar { ...props }>{ children }</Snackbar>;
};
With Action And Explicit DismissPermalink to this section
const WithActionAndExplicitDismiss = ( {
children,
...props
} ) => {
return <Snackbar { ...props }>{ children }</Snackbar>;
};