Notification
Notifications are used to provide feedback to the user. They communicate information about activities, processes, and events in the application.
new tab
import { html, LitElement } from 'lit';
import '@vaadin/vaadin-notification/vaadin-notification';
import { applyTheme } from 'Frontend/generated/theme';
export class Example extends LitElement {
protected createRenderRoot() {
const root = super.createRenderRoot();
// Apply custom theme (only supported if your app uses one)
applyTheme(root);
return root;
}
render() {
return html`
<vaadin-notification-card slot="middle">
Financial report generated
</vaadin-notification-card>
`;
}
}
new tab
The inline .renderer
function is encapsulated by the guard
directive for performance reasons.
See the official Lit documentation for more details.
<vaadin-notification
position="middle"
.opened="${this.notificationOpened}"
@opened-changed="${(e: NotificationOpenedChangedEvent) => {
this.notificationOpened = e.detail.value;
}}"
.renderer="${guard(
[],
(): NotificationRenderer => (root) => {
render(html`Financial report generated`, root);
}
)}"
></vaadin-notification>
Theme Variants
Success
The success
theme variant can be used to display success messages, such as when a task or operation is completed.
new tab
import { html, LitElement } from 'lit';
import '@vaadin/vaadin-notification/vaadin-notification';
import { applyTheme } from 'Frontend/generated/theme';
export class Example extends LitElement {
protected createRenderRoot() {
const root = super.createRenderRoot();
// Apply custom theme (only supported if your app uses one)
applyTheme(root);
return root;
}
render() {
return html`
<vaadin-notification-card theme="success" slot="middle">
Application submitted!
</vaadin-notification-card>
`;
}
}
new tab
The inline .renderer
function is encapsulated by the guard
directive for performance reasons.
See the official Lit documentation for more details.
<vaadin-notification
theme="success"
position="middle"
.opened="${this.notificationOpened}"
@opened-changed="${(e: NotificationOpenedChangedEvent) => {
this.notificationOpened = e.detail.value;
}}"
.renderer="${guard(
[],
(): NotificationRenderer => (root) => {
render(html`Application submitted!`, root);
}
)}"
></vaadin-notification>
Most successful operations should not be declared with notifications, as these can distract the user more than provide useful information. Only use success notifications for operations whose successful completion may otherwise be difficult to discern.
Error
The error
theme variant can be used to display alerts, failures, or warnings.
new tab
import { html, LitElement } from 'lit';
import '@vaadin/vaadin-icon/vaadin-icon';
import '@vaadin/vaadin-lumo-styles/vaadin-iconset';
import '@vaadin/vaadin-button/vaadin-button';
import '@vaadin/vaadin-notification/vaadin-notification';
import '@vaadin/vaadin-ordered-layout/vaadin-horizontal-layout';
import { applyTheme } from 'Frontend/generated/theme';
export class Example extends LitElement {
protected createRenderRoot() {
const root = super.createRenderRoot();
// Apply custom theme (only supported if your app uses one)
applyTheme(root);
return root;
}
render() {
return html`
<vaadin-notification-card theme="error" slot="middle">
<vaadin-horizontal-layout theme="spacing" style="align-items: center;">
<div>Failed to generate report</div>
<vaadin-button theme="tertiary-inline">
<vaadin-icon icon="lumo:cross"></vaadin-icon>
</vaadin-button>
</vaadin-horizontal-layout>
</vaadin-notification-card>
`;
}
}
new tab
<!-- The duration is set to 0-sec to prevent the notification from auto-close. -->
<vaadin-notification
theme="error"
duration="0"
position="middle"
.opened="${this.notificationOpened}"
@opened-changed="${(e: NotificationOpenedChangedEvent) => {
this.notificationOpened = e.detail.value;
}}"
.renderer="${this.renderer}"
></vaadin-notification>
...
renderer: NotificationRenderer = (root) => {
render(
html`
<vaadin-horizontal-layout theme="spacing" style="align-items: center;">
<div>Failed to generate report</div>
<vaadin-button
theme="tertiary-inline"
@click="${() => (this.notificationOpened = false)}"
aria-label="Close"
>
<vaadin-icon icon="lumo:cross"></vaadin-icon>
</vaadin-button>
</vaadin-horizontal-layout>
`,
root
);
};
Error notifications should be persistent, and provide the user with a button that closes the notification and/or allows the user to take appropriate action.
Notifications are non-modal and can be ignored, making them inappropriate for displaying unexpected technical errors that prevent the application from functioning, or situations that require immediate user action. Use a modal Dialog in such situations.
Primary
The primary
theme variant can be used for important informational messages and/or to draw extra attention to it.
new tab
import { html, LitElement } from 'lit';
import '@vaadin/vaadin-notification/vaadin-notification';
import { applyTheme } from 'Frontend/generated/theme';
export class Example extends LitElement {
protected createRenderRoot() {
const root = super.createRenderRoot();
// Apply custom theme (only supported if your app uses one)
applyTheme(root);
return root;
}
render() {
return html`
<vaadin-notification-card theme="primary" slot="middle">
New project plan available
</vaadin-notification-card>
`;
}
}
new tab
The inline .renderer
function is encapsulated by the guard
directive for performance reasons.
See the official Lit documentation for more details.
<vaadin-notification
theme="primary"
position="middle"
.opened="${this.notificationOpened}"
@opened-changed="${(e: NotificationOpenedChangedEvent) => {
this.notificationOpened = e.detail.value;
}}"
.renderer="${guard(
[],
(): NotificationRenderer => (root) => {
render(html`New project plan available`, root);
}
)}"
></vaadin-notification>
Contrast
A high-contrast version that improves legibility and distinguishes it from the rest of the UI.
new tab
import { html, LitElement } from 'lit';
import '@vaadin/vaadin-notification/vaadin-notification';
import { applyTheme } from 'Frontend/generated/theme';
export class Example extends LitElement {
protected createRenderRoot() {
const root = super.createRenderRoot();
// Apply custom theme (only supported if your app uses one)
applyTheme(root);
return root;
}
render() {
return html`
<vaadin-notification-card theme="contrast" slot="middle">
5 tasks deleted
</vaadin-notification-card>
`;
}
}
new tab
The inline .renderer
function is encapsulated by the guard
directive for performance reasons.
See the official Lit documentation for more details.
<vaadin-notification
theme="contrast"
position="middle"
.opened="${this.notificationOpened}"
@opened-changed="${(e: NotificationOpenedChangedEvent) => {
this.notificationOpened = e.detail.value;
}}"
.renderer="${guard(
[],
(): NotificationRenderer => (root) => {
render(html`5 tasks deleted`, root);
}
)}"
></vaadin-notification>
Duration
Notifications stay on-screen for 5 seconds by default. The duration is in milliseconds, and should be based on content and importance:
Use short durations for notifications that have:
Short text content
Lesser importance (for example, operations that finished without errors)
No interactive elements
Use longer durations for notifications that have:
Longer text content
Higher importance (for example, errors)
Interactive elements (for example, links or undo actions)
A duration of at least 5 seconds is recommended to ensure that the user has a chance to see and understand the notification.
Persistent Notifications
Setting the duration to zero disables auto closing, keeping the notification visible until explicitly dismissed by the user. This should be used for notifications that provide vital information to the user, such as errors. Persistent notifications should contain a Button that closes the notification and/or allows the user to take appropriate action.
Less important notifications should not be persistent, and instead disappear automatically after an appropriate delay.
Position
Notifications can be positioned in the viewport in seven non-stretched positions, or stretched across the top or bottom:
new tab
Use the position
attribute in HTML templates, for example, <vaadin-notification position="top-end"></vaadin-notification>
.
render() {
return html`
<vaadin-button @click="${this.show}">top-stretch</vaadin-button>
<vaadin-button @click="${this.show}">top-start</vaadin-button>
<vaadin-button @click="${this.show}">top-center</vaadin-button>
<vaadin-button @click="${this.show}">top-end</vaadin-button>
<vaadin-button @click="${this.show}">middle</vaadin-button>
<vaadin-button @click="${this.show}">bottom-start</vaadin-button>
<vaadin-button @click="${this.show}">bottom-center</vaadin-button>
<vaadin-button @click="${this.show}">bottom-end</vaadin-button>
<vaadin-button @click="${this.show}">bottom-stretch</vaadin-button>
`;
}
show(event: MouseEvent) {
// Use the button label as the location
const position = (event.target as HTMLElement).textContent as NotificationPosition;
const notification = new NotificationElement();
notification.position = position;
notification.renderer = (root) => {
render(html`${position}`, root);
};
document.body.appendChild(notification);
notification.open();
// Remember to clean up the element from the DOM
// if you are not reusing the same notification
notification.addEventListener('opened-changed', () => {
document.body.removeChild(notification);
});
}
Recommendations
Top End or Bottom Start are recommended for most notifications, as these are non-obtrusive but still noticeable.
Middle is the most disruptive position, and only be used for important notifications like errors.
Bottom End is the least obtrusive position, but can go unnoticed.
Stretch notifications, that span the full width of the viewport, are more disruptive, and should be reserved for important notifications whose contents require more space.
Applications with a notification button or drop-down in the header or footer should position notifications to appear in the same part of the screen.
For a consistent user experience, use one or two positions throughout the application.
Avoid using positions that may obstruct important parts of the UI, such as navigation.
Note | The Flow styling issue The Flow notification component renders rich content via an intermediate
|
Stacking
Multiple simultaneously displayed notifications are stacked vertically, depending on their positioning:
When using the bottom half of the screen as the position, a new notification appears below the older notifications.
With the position set to the top half, a new notification appears above the existing notifications.
Size
The notification card is automatically sized based on its content.
In large viewports, the card’s maximum width is ⅓ of the viewport.
In small viewports, the card always takes up the entire width of the viewport.
Interactive Elements
Notifications can contain interactive content like Buttons or links that allow the user to perform related actions.
For example, if an operation fails, the error notification could offer the user the possibility to try again. Or, it could contain a link to a view that allows the user to resolve the problem.
new tab
import { html, LitElement } from 'lit';
import '@vaadin/vaadin-icon/vaadin-icon';
import '@vaadin/vaadin-lumo-styles/vaadin-iconset';
import '@vaadin/vaadin-button/vaadin-button';
import '@vaadin/vaadin-notification/vaadin-notification';
import '@vaadin/vaadin-ordered-layout/vaadin-horizontal-layout';
import { applyTheme } from 'Frontend/generated/theme';
export class Example extends LitElement {
protected createRenderRoot() {
const root = super.createRenderRoot();
// Apply custom theme (only supported if your app uses one)
applyTheme(root);
return root;
}
render() {
return html`
<vaadin-notification-card theme="error" slot="middle">
<vaadin-horizontal-layout theme="spacing" style="align-items: center;">
<div>Failed to generate report</div>
<vaadin-button theme="tertiary-inline" style="margin-left: var(--lumo-space-xl);">
Retry
</vaadin-button>
<vaadin-button theme="tertiary-inline" aria-label="Close">
<vaadin-icon icon="lumo:cross"></vaadin-icon>
</vaadin-button>
</vaadin-horizontal-layout>
</vaadin-notification-card>
`;
}
}
new tab
<!-- The duration is set to 0-sec to prevent the notification from auto-close. -->
<vaadin-notification
theme="error"
duration="0"
position="middle"
.opened="${this.notificationOpened}"
@opened-changed="${(e: NotificationOpenedChangedEvent) => {
this.notificationOpened = e.detail.value;
}}"
.renderer="${this.renderer}"
></vaadin-notification>
...
renderer: NotificationRenderer = (root) => {
render(
html`
<vaadin-horizontal-layout theme="spacing" style="align-items: center;">
<div>Failed to generate report</div>
<vaadin-button
theme="tertiary-inline"
style="margin-left: var(--lumo-space-xl);"
@click="${() => (this.notificationOpened = false)}"
>
Retry
</vaadin-button>
<vaadin-button
theme="tertiary-inline icon"
@click="${() => (this.notificationOpened = false)}"
aria-label="Close"
>
<vaadin-icon icon="lumo:cross"></vaadin-icon>
</vaadin-button>
</vaadin-horizontal-layout>
`,
root
);
};
In situations where the user might want to revert an action, display an Undo button.
new tab
import { html, LitElement } from 'lit';
import '@vaadin/vaadin-icon/vaadin-icon';
import '@vaadin/vaadin-lumo-styles/vaadin-iconset';
import '@vaadin/vaadin-button/vaadin-button';
import '@vaadin/vaadin-notification/vaadin-notification';
import '@vaadin/vaadin-ordered-layout/vaadin-horizontal-layout';
import { applyTheme } from 'Frontend/generated/theme';
export class Example extends LitElement {
protected createRenderRoot() {
const root = super.createRenderRoot();
// Apply custom theme (only supported if your app uses one)
applyTheme(root);
return root;
}
render() {
return html`
<vaadin-notification-card theme="contrast" slot="middle">
<vaadin-horizontal-layout theme="spacing" style="align-items: center;">
<div>5 tasks deleted</div>
<vaadin-button theme="tertiary-inline" style="margin-left: var(--lumo-space-xl);">
Undo
</vaadin-button>
<vaadin-button theme="tertiary-inline" aria-label="Close">
<vaadin-icon icon="lumo:cross"></vaadin-icon>
</vaadin-button>
</vaadin-horizontal-layout>
</vaadin-notification-card>
`;
}
}
new tab
<vaadin-notification
theme="contrast"
duration="10000"
position="middle"
.opened="${this.notificationOpened}"
@opened-changed="${(e: NotificationOpenedChangedEvent) => {
this.notificationOpened = e.detail.value;
}}"
.renderer="${this.renderer}"
></vaadin-notification>
...
renderer: NotificationRenderer = (root) => {
render(
html`
<vaadin-horizontal-layout theme="spacing" style="align-items: center;">
<div>5 tasks deleted</div>
<vaadin-button
theme="tertiary-inline"
style="margin-left: var(--lumo-space-xl);"
@click="${() => (this.notificationOpened = false)}"
>
Undo
</vaadin-button>
<vaadin-button
theme="tertiary-inline"
aria-label="Close"
@click="${() => (this.notificationOpened = false)}"
>
<vaadin-icon icon="lumo:cross"></vaadin-icon>
</vaadin-button>
</vaadin-horizontal-layout>
`,
root
);
};
Notifications can also contain links to relevant information.
new tab
import { html, LitElement } from 'lit';
import '@vaadin/vaadin-icon/vaadin-icon';
import '@vaadin/vaadin-lumo-styles/vaadin-iconset';
import '@vaadin/vaadin-button/vaadin-button';
import '@vaadin/vaadin-notification/vaadin-notification';
import '@vaadin/vaadin-ordered-layout/vaadin-horizontal-layout';
import { applyTheme } from 'Frontend/generated/theme';
export class Example extends LitElement {
protected createRenderRoot() {
const root = super.createRenderRoot();
// Apply custom theme (only supported if your app uses one)
applyTheme(root);
return root;
}
render() {
return html`
<vaadin-notification-card slot="middle">
<vaadin-horizontal-layout theme="spacing" style="align-items: center;">
<div>Jason Bailey mentioned you in <a href="#">Project Q4</a></div>
<vaadin-button theme="tertiary-inline">
<vaadin-icon icon="lumo:cross"></vaadin-icon>
</vaadin-button>
</vaadin-horizontal-layout>
</vaadin-notification-card>
`;
}
}
new tab
<!-- The duration is set to 0-sec to prevent the notification from auto-close. -->
<vaadin-notification
duration="0"
position="middle"
.opened="${this.notificationOpened}"
@opened-changed="${(e: NotificationOpenedChangedEvent) => {
this.notificationOpened = e.detail.value;
}}"
.renderer="${this.renderer}"
></vaadin-notification>
...
renderer: NotificationRenderer = (root) => {
render(
html`
<vaadin-horizontal-layout theme="spacing" style="align-items: center;">
<div>Jason Bailey mentioned you in <a href="#">Project Q4</a></div>
<vaadin-button
theme="tertiary-inline"
aria-label="Close"
@click="${() => (this.notificationOpened = false)}"
>
<vaadin-icon icon="lumo:cross"></vaadin-icon>
</vaadin-button>
</vaadin-horizontal-layout>
`,
root
);
};
Making Interactive Elements Keyboard-Accessible
Take care to ensure that keyboard-only users can access interactive elements in notifications:
Make the notification persistent, to prevent it from disappearing before the user has had a chance to interact with it.
Provide a keyboard shortcut, either to trigger the action itself, or to move focus to the notification card in cases where multiple interactive elements are present.
Make the shortcut discoverable, for example, by displaying it as part of the notification’s content.
new tab
import { html, LitElement } from 'lit';
import '@vaadin/vaadin-button/vaadin-button';
import '@vaadin/vaadin-notification/vaadin-notification';
import '@vaadin/vaadin-ordered-layout/vaadin-horizontal-layout';
import { applyTheme } from 'Frontend/generated/theme';
const isMac = /Macintosh|MacIntel|MacPPC|Mac68K/.test(window.navigator.platform);
export class Example extends LitElement {
protected createRenderRoot() {
const root = super.createRenderRoot();
// Apply custom theme (only supported if your app uses one)
applyTheme(root);
return root;
}
render() {
return html`
<vaadin-notification-card theme="contrast" slot="middle">
<vaadin-horizontal-layout style="align-items: center;">
<div>5 tasks deleted</div>
<vaadin-button theme="primary" style="margin-left: var(--lumo-space-xl);">
Undo ${isMac ? '⌘' : 'Ctrl-'}Z
</vaadin-button>
</vaadin-horizontal-layout>
</vaadin-notification-card>
`;
}
}
new tab
render() {
return html`
<vaadin-notification
theme="contrast"
duration="10000"
position="middle"
.opened="${this.notificationOpened}"
@opened-changed="${(e: NotificationOpenedChangedEvent) => {
this.notificationOpened = e.detail.value;
}}"
.renderer="${this.renderer}"
></vaadin-notification>
`;
}
renderer: NotificationRenderer = (root) => {
render(
html`
<vaadin-horizontal-layout style="align-items: center;">
<div>5 tasks deleted</div>
<vaadin-button
style="margin-left: var(--lumo-space-xl);"
theme="primary"
@click="${() => (this.notificationOpened = false)}"
>
Undo
<!-- Ideally, this should be hidden if the
device does not have a physical keyboard -->
${this.isMac ? '⌘' : 'Ctrl-'}Z
</vaadin-button>
</vaadin-horizontal-layout>
`,
root
);
};
connectedCallback() {
super.connectedCallback();
document.addEventListener('keydown', this.onKeyDown);
}
disconnectedCallback() {
super.disconnectedCallback();
document.removeEventListener('keydown', this.onKeyDown);
}
onKeyDown = (event: KeyboardEvent) => {
if (this.notificationOpened && (event.metaKey || event.ctrlKey) && event.key == 'z') {
// Handle your custom undo logic here
// Avoid triggering the native undo action
event.preventDefault();
this.notificationOpened = false;
}
};
Icons and Other Rich Formatting
Icons and other content formatting can be used to provide information and helpful visual cues, for example, to make errors and success notifications easier to distinguish for users with color blindness.
new tab
import { html, LitElement } from 'lit';
import { customElement } from 'lit/decorators.js';
import '@vaadin/vaadin-avatar/vaadin-avatar';
import '@vaadin/vaadin-button/vaadin-button';
import '@vaadin/vaadin-icon/vaadin-icon';
import '@vaadin/vaadin-icons/vaadin-iconset';
import '@vaadin/vaadin-lumo-styles/vaadin-iconset';
import '@vaadin/vaadin-notification/vaadin-notification';
import { applyTheme } from 'Frontend/generated/theme';
@customElement('notification-rich-preview')
export class Example extends LitElement {
protected createRenderRoot() {
const root = super.createRenderRoot();
// Apply custom theme (only supported if your app uses one)
applyTheme(root);
return root;
}
render() {
return html`
<vaadin-notification-card theme="success" slot="middle">
<vaadin-horizontal-layout theme="spacing" style="align-items: center">
<vaadin-icon icon="vaadin:check-circle"></vaadin-icon>
<div>Application submitted!</div>
<vaadin-button style="margin: 0 0 0 var(--lumo-space-l)">View</vaadin-button>
<vaadin-button theme="tertiary-inline">
<vaadin-icon icon="lumo:cross"></vaadin-icon>
</vaadin-button>
</vaadin-horizontal-layout>
</vaadin-notification-card>
<vaadin-notification-card theme="error" slot="middle">
<vaadin-horizontal-layout theme="spacing" style="align-items: center">
<vaadin-icon icon="vaadin:warning"></vaadin-icon>
<div>Failed to generate report</div>
<vaadin-button style="margin: 0 0 0 var(--lumo-space-l)">Retry</vaadin-button>
<vaadin-button theme="tertiary-inline">
<vaadin-icon icon="lumo:cross"></vaadin-icon>
</vaadin-button>
</vaadin-horizontal-layout>
</vaadin-notification-card>
<vaadin-notification-card slot="middle">
<vaadin-horizontal-layout theme="spacing" style="align-items: center">
<vaadin-avatar name="Jason Bailey"></vaadin-avatar>
<div><b>Jason Bailey</b> mentioned you in <a href="#">Project Q4</a></div>
<vaadin-button theme="tertiary-inline">
<vaadin-icon icon="lumo:cross"></vaadin-icon>
</vaadin-button>
</vaadin-horizontal-layout>
</vaadin-notification-card>
<vaadin-notification-card slot="middle">
<vaadin-horizontal-layout theme="spacing" style="align-items: center">
<vaadin-icon
icon="vaadin:check-circle"
style="color: var(--lumo-success-color)"
></vaadin-icon>
<div>
<b style="color: var(--lumo-success-text-color);">Upload successful</b>
<div
style="font-size: var(--lumo-font-size-s); color: var(--lumo-secondary-text-color);"
>
<b>Financials.xlsx</b> is now available in <a href="#">Documents</a>
</div>
</div>
<vaadin-button theme="tertiary-inline">
<vaadin-icon icon="lumo:cross"></vaadin-icon>
</vaadin-button>
</vaadin-horizontal-layout>
</vaadin-notification-card>
`;
}
}
new tab
The inline .renderer
function is encapsulated by the guard
directive for performance reasons.
See the official Lit documentation for more details.
<vaadin-notification
.renderer="${guard([], () => (root: HTMLElement) => {
render(
html`
<vaadin-horizontal-layout theme="spacing" style="align-items: center">
<vaadin-icon icon="vaadin:check-circle"></vaadin-icon>
<div>Application submitted!</div>
<vaadin-button
style="margin: 0 0 0 var(--lumo-space-l)"
@click="${this.close.bind(this, 1)}"
>View</vaadin-button
>
<vaadin-button
theme="tertiary-inline"
@click="${this.close.bind(this, 1)}"
aria-label="Close"
>
<vaadin-icon icon="lumo:cross"></vaadin-icon>
</vaadin-button>
</vaadin-horizontal-layout>
`,
root
);
})}"
theme="success"
position="middle"
></vaadin-notification>
<vaadin-notification
.renderer="${guard([], () => (root: HTMLElement) => {
render(
html`
<vaadin-horizontal-layout theme="spacing" style="align-items: center">
<vaadin-icon icon="vaadin:warning"></vaadin-icon>
<div>Failed to generate report</div>
<vaadin-button
style="margin: 0 0 0 var(--lumo-space-l)"
@click="${this.close.bind(this, 2)}"
>Retry</vaadin-button
>
<vaadin-button
theme="tertiary-inline"
@click="${this.close.bind(this, 2)}"
aria-label="Close"
>
<vaadin-icon icon="lumo:cross"></vaadin-icon>
</vaadin-button>
</vaadin-horizontal-layout>
`,
root
);
})}"
theme="error"
position="middle"
></vaadin-notification>
<vaadin-notification
.renderer="${guard([], () => (root: HTMLElement) => {
render(
html`
<vaadin-horizontal-layout theme="spacing" style="align-items: center">
<vaadin-avatar name="Jason Bailey"></vaadin-avatar>
<div><b>Jason Bailey</b> mentioned you in <a href="#">Project Q4</a></div>
<vaadin-button
theme="tertiary-inline"
@click="${this.close.bind(this, 3)}"
aria-label="Close"
>
<vaadin-icon icon="lumo:cross"></vaadin-icon>
</vaadin-button>
</vaadin-horizontal-layout>
`,
root
);
})}"
position="middle"
></vaadin-notification>
<vaadin-notification
.renderer="${guard([], () => (root: HTMLElement) => {
render(
html`
<vaadin-horizontal-layout theme="spacing" style="align-items: center">
<vaadin-icon
icon="vaadin:check-circle"
style="color: var(--lumo-success-color)"
></vaadin-icon>
<div>
<b style="color: var(--lumo-success-text-color);">Upload successful</b>
<div
style="font-size: var(--lumo-font-size-s); color: var(--lumo-secondary-text-color)"
>
<b>Financials.xlsx</b> is now available in <a href="#">Documents</a>
</div>
</div>
<vaadin-button
theme="tertiary-inline"
@click="${this.close.bind(this, 4)}"
aria-label="Close"
>
<vaadin-icon icon="lumo:cross"></vaadin-icon>
</vaadin-button>
</vaadin-horizontal-layout>
`,
root
);
})}"
position="middle"
></vaadin-notification>
Best Practices
Use Sparingly
Notifications are disruptive by design and should be used sparingly. Use fewer notifications by reserving them for more important information that may otherwise go unnoticed by the user.
Less urgent notifications can be provided through a link or drop-down in the application header or footer, instead of immediate notifications.
new tab
render() {
return html`
<vaadin-context-menu open-on="click" .renderer="${this.menuRenderer}">
<vaadin-button aria-label="notifications" theme="tertiary">
<vaadin-icon icon="vaadin:bell-o"></vaadin-icon>
<span theme="badge error primary small pill">4</span>
</vaadin-button>
</vaadin-context-menu>
`;
}
menuRenderer = (root: HTMLElement) =>
render(html`<div style="padding: var(--lumo-space-l);">Show notifications here</div>`, root);
Limit Content Length
Aim for one or two lines of content. Notifications should be brief and to the point. More information can be provided through an embedded link or Button.
new tab
import { html, LitElement } from 'lit';
import '@vaadin/vaadin-icon/vaadin-icon';
import '@vaadin/vaadin-lumo-styles/vaadin-iconset';
import '@vaadin/vaadin-button/vaadin-button';
import '@vaadin/vaadin-notification/vaadin-notification';
import { applyTheme } from 'Frontend/generated/theme';
export class Example extends LitElement {
protected createRenderRoot() {
const root = super.createRenderRoot();
// Apply custom theme (only supported if your app uses one)
applyTheme(root);
return root;
}
render() {
return html`
<vaadin-notification-card slot="middle">
<div>
<div>Aria Bailey</div>
<div style="font-size: var(--lumo-font-size-s); color: var(--lumo-secondary-text-color);">
Yeah, I know. But could you help me with...
</div>
</div>
<vaadin-button>View</vaadin-button>
<vaadin-button theme="tertiary-inline">
<vaadin-icon icon="lumo:cross"></vaadin-icon>
</vaadin-button>
</vaadin-notification-card>
`;
}
}
new tab
import { html, LitElement } from 'lit';
import '@vaadin/vaadin-icon/vaadin-icon';
import '@vaadin/vaadin-lumo-styles/vaadin-iconset';
import '@vaadin/vaadin-button/vaadin-button';
import '@vaadin/vaadin-notification/vaadin-notification';
import { applyTheme } from 'Frontend/generated/theme';
export class Example extends LitElement {
protected createRenderRoot() {
const root = super.createRenderRoot();
// Apply custom theme (only supported if your app uses one)
applyTheme(root);
return root;
}
render() {
return html`
<vaadin-notification-card slot="middle">
<div>
<div>New message from Aria Bailey</div>
<div style="font-size: var(--lumo-font-size-s); color: var(--lumo-secondary-text-color);">
Yeah, I know. But could you help me with this. I’m not sure where the bug is in my CSS?
The checkmark doesn’t get the right color. I’m trying to use the CSS custom properties
from our design system, but for some reason it’s not working.
</div>
</div>
<vaadin-button theme="tertiary-inline">
<vaadin-icon icon="lumo:cross"></vaadin-icon>
</vaadin-button>
</vaadin-notification-card>
`;
}
}