Shows a brief message about an operation, with an optional action.
The component supports the
Invoker Commands API.
A button with command="--show", "--hide" or "--toggle" and a
commandfor that points to this element calls the matching method.
- Slots
-
default— The content of the snackbar. -
action— The action of the snackbar, usually a button. Replaces the default action button.
- CSS Parts
-
base— The base wrapper of the snackbar component. -
message— The snackbar message. -
action— The default snackbar action button. -
action-container— The area holding the actions.
Properties
Section titled "Properties"actionText
Section titled "actionText"The text of the action button.
actionText: string | undefined displayTime
Section titled "displayTime"The time in milliseconds that the component stays visible. The time stops while the pointer or the keyboard focus is in the component, and starts again from the full value when both leave. A value of 0 or less keeps the component open.
displayTime: number keepOpen
Section titled "keepOpen"Whether the component stays open after the displayTime is over.
keepOpen: boolean Whether the component is open.
Setting it skips the fade. Use the show(), hide() and toggle()
methods for a fade.
open: boolean position
Section titled "position"The position of the component in the viewport or in the container.
position: AbsolutePosition positioning
Section titled "positioning"The positioning strategy of the component.
viewport - positions against the viewport, ignoring every ancestor.
container - positions inside the bounding box of the closest visible
ancestor, at the place that position sets.
positioning: NotificationPositioning Methods
Section titled "Methods"connectedCallback
Section titled "connectedCallback"Invoked when the component is added to the document's DOM.
In connectedCallback() you should setup tasks that should only occur when
the element is connected to the document. The most common of these is
adding event listeners to nodes external to the element, like a keydown
event handler added to the window.
``
Typically, anything done in connectedCallback() should be undone when the
element is disconnected, in disconnectedCallback().
connectedCallback(): void Returns void
disconnectedCallback
Section titled "disconnectedCallback"Invoked when the component is removed from the document's DOM.
This callback is the main signal to the element that it may no longer be
used. disconnectedCallback() should ensure that nothing is holding a
reference to the element (such as event listeners added to nodes external
to the element), so that it is free to be garbage collected.
``
An element may be re-connected after being disconnected.
disconnectedCallback(): void Returns void
Closes the component. Resolves to false when it is already closed or
fades out, or when open is set to false and then to true during the
fade-out.
hide(): Promise<boolean> Returns Promise<boolean>
Opens the component, also during the fade-out of hide(). When it is
already open, the display time starts again, and the promise resolves to
false. It also resolves to false when container positioning finds no
visible ancestor, or when open is set to false during the fade-in.
show(): Promise<boolean> Returns Promise<boolean>
toggle
Section titled "toggle"Opens the component when it is closed, and closes it when it is open.
Resolves to true when the state changes.
toggle(): Promise<boolean> Returns Promise<boolean>
Events
Section titled "Events"onAction
Section titled "onAction"Emitted when the user clicks the default action button or the content of the
onAction(args: CustomEvent<void>): void Parameters
- args:
CustomEvent<void>