NotificationElement
<vaadin-notification> is a Web Component providing accessible and customizable notifications (toasts).
Rendering
The content of the notification can be populated by using the renderer callback function.
The renderer function provides root, notification arguments. Generate DOM content, append it to the root element and control the state of the host element by accessing notification. Before generating new content, users are able to check if there is already content in root for reusing it.
<vaadin-notification id="notification"></vaadin-notification>const notification = document.querySelector('#notification');
notification.renderer = function(root, notification) {
root.textContent = "Your work has been saved";
};Renderer is called on the opening of the notification. DOM generated during the renderer call can be reused in the next renderer call and will be provided with the root argument. On first call it will be empty.
Styling
<vaadin-notification> uses <vaadin-notification-card> internal themable component as the actual visible notification cards.
The following shadow DOM parts of the <vaadin-notification-card> are available for styling:
| Part name | Description |
|---|---|
overlay | The notification container |
content | The content of the notification |
The following custom CSS properties are available for styling:
| Custom CSS property |
|---|
--vaadin-notification-background |
--vaadin-notification-border-color |
--vaadin-notification-border-radius |
--vaadin-notification-border-width |
--vaadin-notification-container-gap |
--vaadin-notification-padding |
--vaadin-notification-shadow |
--vaadin-notification-viewport-inset |
--vaadin-notification-width |
See Styling Components documentation.
Note: the theme attribute value set on <vaadin-notification> is propagated to the internal <vaadin-notification-card>.
Properties
A space-delimited list of CSS class names to set on the overlay element. This property does not affect other CSS class names set manually via JS.
Custom function for rendering the content of the notification. Receives two arguments:
Functions
Requests an update for the content of the notification. While performing the update, it invokes the renderer passed in the renderer property.
Shows a notification with the given content. By default, positions the notification at bottom-start and uses a 5 second duration. An options object can be passed to configure the notification. The options object has the following structure: