Notification
A notification is a box with a title, a text and, if you want, buttons. It stands at a corner or at the top or bottom edge of the window, closes itself after a time, and takes no focus. It is heavier than a message: it says more, and it stays at the edge of the window and not above the content. You open it with a call from code, from anywhere, not by writing an element in a template.
When to use
- Use it for feedback that needs a title and a text: a finished upload, a failed sync, a new version, a message from someone.
- A short feedback that says one thing is a
Message. A decision the user must make needs a dialog (Modal). - A notification goes away by itself, so do not put information in it that the user must be able to find again, or give it
duration: 0and let the user close it.
Examples
<script lang="ts">
import { Button, notification } from 'svelte-ant-design';
</script>
<!-- A call from anywhere shows a notification at the top right: no setup and no markup. It goes after 4.5 s. -->
<Button
type="primary"
onclick={() =>
notification.open({
title: 'Notification title',
description: 'This is the content of the notification. A title, and a text under it.'
})}
>
Open the notification
</Button>
open: no type icon
<script lang="ts">
import { Button, notification } from 'svelte-ant-design';
const text = 'The type gives the icon, and a screen reader the type word before the title.';
</script>
<!-- Four kinds with an icon, and `open`, which has none. `error` and `warning` are read out at once, the others wait. -->
<div class="stack">
<div class="row">
<Button onclick={() => notification.success({ title: 'Saved', description: text })}>success</Button>
<Button onclick={() => notification.info({ title: 'New version', description: text })}>info</Button>
<Button onclick={() => notification.warning({ title: 'Almost full', description: text })}>warning</Button>
<Button onclick={() => notification.error({ title: 'Upload failed', description: text })}>error</Button>
</div>
<div class="field">
<span class="caption">open: no type icon</span>
<Button onclick={() => notification.open({ title: 'No icon', description: text })}>open</Button>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
<script lang="ts">
import { Button, notification, type NotificationPlacement } from 'svelte-ant-design';
const top: NotificationPlacement[] = ['topLeft', 'top', 'topRight'];
const bottom: NotificationPlacement[] = ['bottomLeft', 'bottom', 'bottomRight'];
const show = (placement: NotificationPlacement) =>
notification.info({ title: placement, description: 'The newest stands nearest the window edge.', placement, duration: 6 });
</script>
<!-- Six places. Each is its own list: the newest notification is nearest the edge, the older ones are pushed away from it. -->
<div class="stack">
<div class="row">
{#each top as placement (placement)}
<Button onclick={() => show(placement)}>{placement}</Button>
{/each}
</div>
<div class="row">
{#each bottom as placement (placement)}
<Button onclick={() => show(placement)}>{placement}</Button>
{/each}
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
</style>
duration 10
duration 0: until it is closed
<script lang="ts">
import { Button, notification } from 'svelte-ant-design';
let close: (() => void) | undefined;
</script>
<!-- `duration` is in seconds (default 4.5). `0` or `false` keeps the notification until it is closed. -->
<div class="stack">
<div class="field">
<span class="caption">duration 10</span>
<Button onclick={() => notification.info({ title: 'Ten seconds', description: 'It waits longer than usual.', duration: 10 })}>10 s</Button>
</div>
<div class="field">
<span class="caption">duration 0: until it is closed</span>
<div class="row">
<Button onclick={() => (close = notification.warning({ title: 'Stays', description: 'Close it with the cross, or with the other button.', duration: 0 }))}>
Open
</Button>
<Button onclick={() => close?.()}>Close it by code</Button>
</div>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
<script lang="ts">
import { Button, notification } from 'svelte-ant-design';
// The same key updates the notification in place: the box stays where it is, and a screen reader reads the new text.
function run() {
notification.info({ title: 'Uploading', description: 'The file is on its way.', key: 'upload', duration: 0 });
setTimeout(() => notification.success({ title: 'Uploaded', description: 'The file is on the server.', key: 'upload', duration: 4 }), 1800);
}
</script>
<Button onclick={run}>Upload</Button>
<script lang="ts">
import { Button, notification } from 'svelte-ant-design';
const key = 'actions';
const undo = () => notification.destroy(key);
</script>
<!-- `actions` is content under the text, at the end: usually buttons. They are your elements, so the keyboard reaches them
after the text and before the close button. -->
{#snippet actions()}
<Button size="small" onclick={undo}>Undo</Button>
<Button size="small" type="primary" onclick={undo}>Keep</Button>
{/snippet}
<Button onclick={() => notification.info({ title: 'Message moved', description: 'It is in the archive now.', actions, key, duration: 0 })}>
With actions
</Button>
icon: a string
icon: a snippet
icon: false
<script lang="ts">
import { Button, notification } from 'svelte-ant-design';
</script>
{#snippet star()}<span style="color: gold; font-size: 24px">★</span>{/snippet}
<!-- `icon` replaces the icon of the type: a string (an emoji), a snippet, or `false` for none. -->
<div class="stack">
<div class="field">
<span class="caption">icon: a string</span>
<Button onclick={() => notification.success({ title: 'Launched', description: 'The icon is an emoji.', icon: '🚀' })}>string</Button>
</div>
<div class="field">
<span class="caption">icon: a snippet</span>
<Button onclick={() => notification.open({ title: 'Starred', description: 'The icon is a snippet.', icon: star })}>snippet</Button>
</div>
<div class="field">
<span class="caption">icon: false</span>
<Button onclick={() => notification.error({ title: 'Without icon', description: 'The type word is still read by a screen reader.', icon: false })}>false</Button>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
closable: false
closeIcon: a string
closeIcon: a snippet
<script lang="ts">
import { Button, notification } from 'svelte-ant-design';
</script>
{#snippet word()}Close{/snippet}
<!-- The close button is there by default. `closable: false` or `closeIcon: false` removes it; `closeIcon` replaces the cross. -->
<div class="stack">
<div class="field">
<span class="caption">closable: false</span>
<Button onclick={() => notification.info({ title: 'No close button', description: 'It goes by itself.', closable: false })}>closable false</Button>
</div>
<div class="field">
<span class="caption">closeIcon: a string</span>
<Button onclick={() => notification.info({ title: 'A text button', description: 'The name of the button stays "Close".', closeIcon: '✕', duration: 8 })}>string</Button>
</div>
<div class="field">
<span class="caption">closeIcon: a snippet</span>
<Button onclick={() => notification.info({ title: 'A snippet button', description: 'Any content is the icon.', closeIcon: word, duration: 8 })}>snippet</Button>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
showProgress, duration 8: hold the pointer over it
showProgress, pauseOnHover: false
<script lang="ts">
import { Button, notification } from 'svelte-ant-design';
</script>
<!-- `showProgress` draws a strip that runs down with the time left. It is drawn from the timer that closes the notification, so it
stands still while the pointer or the focus holds it. It is decorative: it is not announced. -->
<div class="stack">
<div class="field">
<span class="caption">showProgress, duration 8: hold the pointer over it</span>
<Button onclick={() => notification.info({ title: 'Progress', description: 'The strip waits when the timer waits.', showProgress: true, duration: 8 })}>
with a strip
</Button>
</div>
<div class="field">
<span class="caption">showProgress, pauseOnHover: false</span>
<Button onclick={() => notification.info({ title: 'No pause', description: 'It goes on while you hold the pointer.', showProgress: true, pauseOnHover: false, duration: 8 })}>
does not pause
</Button>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
pauseOnHover (the default), duration 5: keep the pointer over it
pauseOnHover: false
duration 5: Tab to the close button, and it waits for you
<script lang="ts">
import { Button, notification } from 'svelte-ant-design';
</script>
<!-- Hover (a mouse or a pen, not a touch) and focus inside stop the timer; it goes on with the time that was left. The timer also
waits while the page is hidden. -->
<div class="stack">
<div class="field">
<span class="caption">pauseOnHover (the default), duration 5: keep the pointer over it</span>
<Button onclick={() => notification.info({ title: 'Hover me', description: 'I stay while you do.', duration: 5 })}>pauses</Button>
</div>
<div class="field">
<span class="caption">pauseOnHover: false</span>
<Button onclick={() => notification.info({ title: 'I go on', description: 'Whatever you do.', duration: 5, pauseOnHover: false })}>does not pause</Button>
</div>
<div class="field">
<span class="caption">duration 5: Tab to the close button, and it waits for you</span>
<Button onclick={() => notification.warning({ title: 'Focus holds it', description: 'Focus inside the box stops the timer.', duration: 5 })}>holds on focus</Button>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
</style>
stack on (the default), threshold 3
<script lang="ts">
import { Button, Switch, notification } from 'svelte-ant-design';
let stacked = $state(true);
let opened = $state(0);
// `stack` is a setting of notification.config(): on by default, `{ threshold }` sets the number, `false` turns it off.
$effect(() => {
notification.config({ stack: stacked ? undefined : false });
return () => notification.config({ stack: undefined });
});
</script>
<!-- Past the threshold (3) the older notifications of a place lie behind the newest one; the pointer or the focus opens the pile,
and every timer waits while it is open. -->
<div class="stack">
<div class="row">
<Switch bind:checked={stacked} aria-label="stack" />
<span>stack {stacked ? 'on (the default), threshold 3' : 'off'}</span>
</div>
<div class="row">
<Button onclick={() => notification.info({ title: `Notification ${++opened}`, description: 'This is a stacked notification.', duration: 12 })}>Open</Button>
<Button onclick={() => notification.destroy()}>Destroy all</Button>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
</style>
maxCount not set
<script lang="ts">
import { Button, Switch, notification } from 'svelte-ant-design';
let limited = $state(false);
let opened = $state(0);
let pushed = $state(0);
// maxCount is a setting of notification.config(): it counts the notifications of all places together. undefined takes it back
// to the default (no limit), so the other examples of the page are not limited.
$effect(() => {
notification.config({ maxCount: limited ? 3 : undefined });
return () => notification.config({ maxCount: undefined });
});
</script>
<div class="stack">
<div class="row">
<Switch bind:checked={limited} aria-label="maxCount 3" />
<span>maxCount {limited ? 3 : 'not set'}</span>
</div>
<div class="field">
<div class="row">
<Button
onclick={() =>
notification.info({
title: `Notification ${++opened}`,
description: 'The oldest closes to make room.',
duration: 0,
onclose: (reason) => reason === 'replaced' && pushed++
})}
>
Open one
</Button>
<Button onclick={() => notification.destroy()}>Close all</Button>
</div>
<span role="status">{opened} opened, pushed out by the limit: {pushed}</span>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
</style>
class, style: on the box
classNames, styles: the parts (root, icon, section, title, description, actions, close, progress)
props: data-* and aria-* on the box
<script lang="ts">
import { Button, notification } from 'svelte-ant-design';
</script>
<div class="stack">
<div class="field">
<span class="caption">class, style: on the box</span>
<Button onclick={() => notification.info({ title: 'Styled box', description: 'A class and a style.', class: 'fancy', style: { 'border-radius': '24px' } })}>
class and style
</Button>
</div>
<div class="field">
<span class="caption">classNames, styles: the parts (root, icon, section, title, description, actions, close, progress)</span>
<Button
onclick={() =>
notification.success({
title: 'Styled parts',
description: 'The box, the title and the strip.',
showProgress: true,
classNames: { title: 'fancy-title' },
styles: { root: { background: 'var(--ads-color-primary-solid)', color: '#fff' }, icon: { color: '#fff' }, close: { color: '#fff' } }
})}
>
classNames and styles
</Button>
</div>
<div class="field">
<span class="caption">props: data-* and aria-* on the box</span>
<Button onclick={() => notification.info({ title: 'With attributes', props: { 'data-testid': 'my-note', 'aria-label': 'Custom label' } })}>props</Button>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
/* The notification is drawn outside this component, so a class that styles it is global here. */
:global(.fancy) {
outline: 2px dashed var(--ads-color-primary);
}
:global(.fancy-title) {
font-weight: 600;
letter-spacing: 0.02em;
}
</style>
box clicks: 0; closed by: —
<script lang="ts">
import { Button, notification } from 'svelte-ant-design';
let clicked = $state(0);
let reason = $state('');
</script>
<!-- `onclick` is called when the box is clicked (not the close button). `onclose` is called once, when the notification starts to
close, with the reason: 'timeout', 'user' (the close button, Escape), 'replaced' (the limit) or 'destroy' (code). -->
<div class="stack">
<div class="field">
<Button
onclick={() =>
notification.info({
title: 'Click me, or close me',
description: 'Wait, close it, or press Escape inside it.',
duration: 6,
onclick: () => clicked++,
onclose: (why) => (reason = why)
})}
>
Open
</Button>
<span role="status">box clicks: {clicked}; closed by: {reason || '—'}</span>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
</style>
<script lang="ts">
import { Button, notification } from 'svelte-ant-design';
</script>
<!-- Title, description and actions are a string, a number or a snippet. A snippet is drawn in the layer, so it sees the context of the
place where the host is, not of the component that wrote it. -->
{#snippet title()}<strong>Rich</strong> <em>title</em>{/snippet}
{#snippet description()}A link to <a href="#content">the docs</a> and <code>code</code>.{/snippet}
<Button onclick={() => notification.info({ title, description, duration: 10 })}>Snippets</Button>
<NotificationHost placement="bottomLeft" bottom={72} ... /> not mounted
<script lang="ts">
import { Button, NotificationHost, Switch, notification } from 'svelte-ant-design';
let mounted = $state(false);
</script>
<!-- <NotificationHost> draws the notifications where you put it. Its props are the settings and win over notification.config(). Without one the library
makes its own layer. Only one host is active at a time. -->
{#if mounted}
<NotificationHost placement="bottomLeft" bottom={72} duration={8} labels={{ close: 'Dismiss', success: 'Done', error: 'Failed' }} />
{/if}
<div class="stack">
<div class="row">
<Switch bind:checked={mounted} aria-label="NotificationHost" />
<span><NotificationHost placement="bottomLeft" bottom={72} ... /> {mounted ? 'mounted' : 'not mounted'}</span>
</div>
<div class="row">
<Button onclick={() => notification.success({ title: 'Saved' })}>success</Button>
<Button onclick={() => notification.error({ title: 'Upload' })}>error</Button>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
</style>
<script lang="ts">
import { Button, notification } from 'svelte-ant-design';
let opened = $state(0);
</script>
<!-- `notification.destroy(key)` closes one, `notification.destroy()` closes every notification. -->
<div class="stack">
<div class="row">
<Button onclick={() => notification.info({ title: `Notification ${++opened}`, key: `n${opened}`, duration: 0 })}>Open</Button>
<Button onclick={() => notification.destroy(`n${opened}`)}>Close the last</Button>
<Button onclick={() => notification.destroy()}>Destroy all</Button>
</div>
</div>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
</style>
a modal dialog
<script lang="ts">
import { tick } from 'svelte';
import { Button, notification } from 'svelte-ant-design';
const KEY = 'container-dialog';
let dialog = $state<HTMLDialogElement | null>(null);
// Null before the first press; then where the layer was found: in the body or in the dialog.
let placed = $state<'body' | 'dialog' | null>(null);
// `container` is a setting of notification.config(): the element that the layer is put in (the body by default). A native modal
// <dialog> is shown in the top layer of the browser, over everything that is outside of it, and nothing outside it can be reached.
// So a layer in the body is covered by the dialog, and a layer in the dialog stands above it and can be used. The setting is
// given back (and the notification closed) when the dialog closes, and when the example is left, so that the page is not touched.
async function show(inDialog: boolean) {
if (!dialog) return;
notification.config({ container: inDialog ? dialog : undefined });
notification.info({
key: KEY,
title: inDialog ? 'In the dialog' : 'In the body',
description: inDialog ? 'Above the dialog, and it can be closed.' : 'Behind the dialog.',
duration: 8,
props: { 'data-demo': 'container' }
});
await tick();
placed = dialog.contains(document.querySelector('[data-demo="container"]')) ? 'dialog' : 'body';
}
function release() {
notification.destroy(KEY);
notification.config({ container: undefined });
placed = null;
}
$effect(() => {
return () => notification.config({ container: undefined });
});
</script>
<div class="stack">
<div class="field">
<span class="caption">a modal dialog</span>
<div class="row">
<Button onclick={() => dialog?.showModal()}>Open the dialog</Button>
</div>
</div>
</div>
<dialog bind:this={dialog} aria-label="The container example" onclose={release}>
<div class="stack">
<div class="field">
<span class="caption">container: not set (the body)</span>
<Button onclick={() => show(false)}>Show a notification</Button>
<span class="out" role="status">
{#if placed === 'body'}
The layer is in the body. The dialog covers it, and the notification cannot be reached.
{:else}
Press to see where the layer goes.
{/if}
</span>
</div>
<div class="field">
<span class="caption">container: the dialog</span>
<Button onclick={() => show(true)}>Show a notification</Button>
<span class="out" role="status">
{#if placed === 'dialog'}
The layer is in the dialog. The notification stands above it and can be closed.
{:else}
Press to see where the layer goes.
{/if}
</span>
</div>
<div class="row">
<Button onclick={() => dialog?.close()}>Close the dialog</Button>
</div>
</div>
</dialog>
<style>
.stack {
display: grid;
justify-items: start;
gap: 16px;
}
.field {
display: grid;
justify-items: start;
gap: 8px;
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.out {
min-height: 36px;
color: var(--ads-color-text-secondary);
font-size: 12px;
line-height: 18px;
}
dialog {
box-sizing: border-box;
width: min(420px, calc(100vw - 32px));
padding: 20px 24px;
border: 1px solid var(--ads-color-border);
border-radius: var(--ads-radius-lg);
background: var(--ads-color-bg-container);
color: var(--ads-color-text);
}
/* Dark enough to show that what stands under it is covered. */
dialog::backdrop {
background: rgb(0 0 0 / 55%);
}
</style>
API
Options of a notification
| Property | Description | Type | Default |
|---|---|---|---|
| title | The first line: a string, a number (0 is shown) or a snippet. Required. This is the name title that Ant Design React 6 uses (message is deprecated there). | NotificationContent | — |
| description | The text under the title. Optional: a title alone is a valid notification. | NotificationContent | — |
| actions | Content under the text, at the inline end: usually buttons. The elements you put here are the ones the keyboard reaches (React actions, Vue btn). | NotificationContent | — |
| icon | Replaces the icon of the type; false removes it. open has no icon unless one is given. | string | Snippet | false | the icon of the type |
| duration | Seconds before the notification goes away. 0 or false keeps it until it is closed. A negative or non-finite value falls back to the default (with a warning while developing). Angular counts in milliseconds; we do not. | number | false | 4.5 |
| key | A call with the key of an open notification updates that notification in place (new type, texts and options; the timer starts again). Without one a key is generated. | string | number | generated |
| placement | Where it stands: its own place, or the default of the host and of notification.config(). | 'top' | 'topLeft' | 'topRight' | 'bottom' | 'bottomLeft' | 'bottomRight' | 'topRight' |
| closable | Shows the close button. The default of the host and of notification.config() applies when it is not set. | boolean | true |
| closeIcon | Replaces the cross of the close button; false removes the button. The name of the button for a screen reader stays labels.close. The object form of React closable is not taken: it is closeIcon and onclose. | string | Snippet | false | the cross |
| showProgress | Shows a strip at the bottom of the box that runs down with the time left. It stands still while the timer does, and there is none with duration: 0. | boolean | false |
| pauseOnHover | Holds the timer while the pointer (a mouse or a pen) is over the box. Focus inside, an open pile and a hidden page hold it whatever this says. | boolean | true |
| role | Overrides the role. By default error and warning are alert (read out at once) and the others status. | 'alert' | 'status' | by type |
| class | Extra classes of the box. | string | — |
| style | Inline style of the box: a string, or an object of CSS properties (kebab-case or custom properties; numbers are written as they are). | string | Record<string, string | number> | — |
| classNames | Extra classes for the parts. A value here wins over the one of the host and of notification.config(). | { root?, icon?, section?, title?, description?, actions?, close?, progress? } | — |
| styles | The same for inline styles, as objects. | { root?, icon?, section?, title?, description?, actions?, close?, progress? } | — |
| props | Attributes put on the box (React props): data-* and aria-*. | Record<`data-${string}` | `aria-${string}`, string> | — |
| onclick | Called with the event when the box is clicked, not when its close button is. A click does not close the notification. | (event: MouseEvent) => void | — |
| onclose | Called once, when the notification starts to close, with the reason: the time ran out, the user closed it (the close button or Escape), the limit pushed it out, or code closed it (destroy or the returned function). Angular says only whether the user closed it; React and Vue pass nothing. | (reason: 'timeout' | 'user' | 'replaced' | 'destroy') => void | — |
Methods
| Property | Description | Type | Default |
|---|---|---|---|
| notification.open(options) | Opens a notification with no type icon, or updates the open one with the same key. Returns a function that closes it. It is not thenable (Message's is). | () => void | — |
| notification.info | success | error | warning(options) | One method for each kind, with the same options. Without a window (on a server) every call does nothing and returns a function that does nothing. | () => void | — |
| notification.destroy(key?) | Closes the notification with this key, or every notification. Each one runs its normal exit and its onclose with the reason 'destroy'. | void | — |
| notification.config(options) | Sets defaults for every notification from now on (the settings table below). A setting given as { top: undefined } goes back to its default. | void | — |
Settings: notification.config() and the props of NotificationHost
| Property | Description | Type | Default |
|---|---|---|---|
| top | Distance of the top places from the top of the window. A number is pixels. | number | string | 24 |
| bottom | Distance of the bottom places from the bottom of the window. A number is pixels. | number | string | 24 |
| placement | The place of every notification that does not name one. | 'top' | 'topLeft' | 'topRight' | 'bottom' | 'bottomLeft' | 'bottomRight' | 'topRight' |
| duration | Default duration in seconds. 0 and false never close. | number | false | 4.5 |
| maxCount | At most this many open notifications, in all places together; the oldest is closed to make room (reason 'replaced'). Ant Design React and Angular count the same way, Vue counts for each place. | number | — |
| container | The element that the layer is put in. Only where it sits in the page: the layer stays position: fixed, drawn at the window (Ant Design getContainer). Useful for a native modal <dialog>, which covers everything outside of it. | HTMLElement | (() => HTMLElement) | document.body |
| closable | Default of closable. | boolean | true |
| closeIcon | Default of closeIcon. | string | Snippet | false | the cross |
| showProgress | Default of showProgress. | boolean | false |
| pauseOnHover | Default of pauseOnHover. | boolean | true |
| labels | The type word read before the title (an empty word is none, which is the default of open), and the name of the close button. Pass a translation here: the library has no locale system yet. | { open?, info?, success?, error?, warning?, close? } | { info: "Info", success: "Success", error: "Error", warning: "Warning", close: "Close" } |
| classNames | Defaults for the parts of every notification, and the two parts of a place: list (the scrolling column) and listContent (the rows). | { root?, icon?, section?, title?, description?, actions?, close?, progress?, list?, listContent? } | — |
| styles | The same for inline styles, as objects. | { root?, icon?, section?, title?, description?, actions?, close?, progress?, list?, listContent? } | — |
| stack | On by default (as in Ant Design React): past the threshold (3) the older notifications of a place lie behind the newest, and the pointer or focus opens the pile. false turns it off, { threshold } changes the number. | boolean | { threshold?: number } | true |
Differences from Ant Design: the layer is made by the library (the React
useNotification and contextHolder are replaced by <NotificationHost>); title and actions are the current React names (message and btn are deprecated there); stack is on by default as in React; the newest notification stands nearest the window edge in every place, as in React; a role per type and a hidden type word (React: role="alert" for all); the timer also waits for focus, an open pile and a hidden page; onclose carries the reason, and a call returns a function that closes the notification; duration is in seconds as in React and Vue (Angular: milliseconds). Not taken: the Vue warn alias, prefixCls, rtl (the direction is inherited) and the object form of closable. API inspired by Ant Design (MIT); the implementation is original for Svelte.Design tokens
| Token | Description | Default |
|---|---|---|
| --ads-notification-z-index | Layer of the notifications, above the messages (2010) and every popup (the tooltip is 1070). | 2050 |
| --ads-notification-width | Width of the box. It is never wider than the window. | 384px |
| --ads-notification-top | Distance of the top places from the top of the window, when top is not set. | 24px |
| --ads-notification-bottom | Distance of the bottom places from the bottom of the window, when bottom is not set. | 24px |
| --ads-notification-margin | Space kept free at the sides of the window, and at the far end of a place (it also leaves room for the shadow). | 24px |
| --ads-notification-gap | Gap between two notifications. | 16px |
| --ads-notification-bg | Background of the box. In the dark theme #1f1f1f. | #ffffff |
| --ads-notification-color | Text color. In the dark theme 85% white. | rgba(0, 0, 0, 0.88) |
| --ads-notification-padding-block | Padding of the box above and below. | 20px |
| --ads-notification-padding-inline | Padding of the box at the sides. The close button stands at this distance from the edge. | 24px |
| --ads-notification-padding | Padding of the box (the two above). | var(--ads-notification-padding-block) var(--ads-notification-padding-inline) |
| --ads-notification-line-height | Height of a line of the description. | 22px |
| --ads-notification-radius | Corner radius of the box. | 8px |
| --ads-notification-shadow | Shadow of the box. | 0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 9px 28px 8px rgba(0, 0, 0, 0.05) |
| --ads-notification-title-size | Font size of the title. | 16px |
| --ads-notification-title-line-height | Height of a line of the title; the icon and the close button are centred on it. | 24px |
| --ads-notification-description-gap | Gap between the title and the description. | 8px |
| --ads-notification-actions-gap | Gap between the text and the actions. | 12px |
| --ads-notification-icon-size | Size of the icon. | 24px |
| --ads-notification-icon-gap | Gap between the icon and the text. | 12px |
| --ads-notification-icon-info | Color of the info icon. | #1677ff |
| --ads-notification-icon-success | Color of the success icon. tokens-accessible.css darkens it to #389e0d (3:1 on the white box). | #52c41a |
| --ads-notification-icon-error | Color of the error icon. | #ff4d4f |
| --ads-notification-icon-warning | Color of the warning icon. tokens-accessible.css darkens it to #c27c00. | #faad14 |
| --ads-notification-close-size | Size of the close button: 24px, the smallest target of WCAG 2.5.8 (Ant Design has 22px). | 24px |
| --ads-notification-close-icon-size | Size of the cross in the close button. | 14px |
| --ads-notification-close-room | Space kept free at the end of the first line of the title, for the close button. | 26px |
| --ads-notification-close-padding | Air at both ends of a close button that holds more than the cross, a word for example; the cross stays a 24 px square. | 4px |
| --ads-notification-close-color | Color of the close button. tokens-accessible.css makes it rgba(0, 0, 0, 0.65) (4.5:1 on the box). | rgba(0, 0, 0, 0.45) |
| --ads-notification-close-color-hover | Color of the close button on hover. | rgba(0, 0, 0, 0.88) |
| --ads-notification-close-bg | Background of the close button at rest. | transparent |
| --ads-notification-close-bg-hover | Background of the close button on hover. | rgba(0, 0, 0, 0.06) |
| --ads-notification-progress-bg | Fill of the progress strip. | linear-gradient(90deg, #69b1ff, #1677ff) |
| --ads-notification-progress-track | Track of the progress strip. | rgba(0, 0, 0, 0.04) |
| --ads-notification-progress-height | Height of the progress strip. | 2px |
| --ads-notification-progress-inset | Distance of the progress strip from the sides of the box. | 8px |
| --ads-notification-progress-radius | Corner radius of the progress strip. | 8px |
| --ads-notification-motion-offset | How far from its place a notification starts to come in and ends to leave (from its side: the right places from the right, top from above). | 64px |
| --ads-notification-stack-offset | Step between the rows of a pile. | 8px |
| --ads-notification-stack-scale-step | How much smaller each row of a pile is than the one in front of it (the scale stops at the second step). | 0.06 |
Accessibility
errorandwarningarerole="alert"and are read out at once;info,successandopenarerole="status"and wait for the reader to finish. Ant Design React givesrole="alert"to all, which interrupts a reader for a plain “Saved”; theroleoption sets it per notification.- The icon is decorative. A hidden word before the title names the type (“Error: Upload failed”), so the type is not only a color and a shape. Pass translations in
labels: the library has no locale system yet and the default is English. - A notification never takes focus. What can be focused in it is the close button and the elements you put in
actions; the close button is 24px, the target size of WCAG 2.5.8.Escapecloses the notification that has focus inside it. - The timer waits while the pointer is over the notification, while focus is inside it, while a pile is open and while the page is hidden. A notification that must stay needs
duration: 0, and the close button lets the user dismiss it (WCAG 2.2.1, time limits). - The layer is the last element of its container, so the keyboard reaches the buttons of a notification only after the rest of the page, and there is no shortcut that moves focus to the notifications. In a pile the older notifications are
inertand hidden from a screen reader; the pile opens when focus comes into it, so a keyboard user reaches them. - Contrast: the text is about 15:1 on the box; the type icons are held to 3:1 and the close button to 4.5:1 (in the dark theme, and in the light theme with
tokens-accessible.css, which darkens the green, the amber and the close button). - In forced-colors modes such as Windows High Contrast the box, the close button and the progress strip are drawn with a border. The motion (the box comes in from the side of its place and fades) is off under
prefers-reduced-motion; the timer and the strip are the same. A touch does not hold the timer and does not open a pile. - Checked with a real screen reader (Orca with Firefox): it reads the role, the type word, the title, the description, the new text after an update by key and the name of the close button. Not checked: whether a screen reader announces a notification when it opens (the Orca setup does not speak even a plain
role="alert"), NVDA, JAWS, VoiceOver, a phone screen reader, a real touch device (touch is emulated in Chromium) and a real Safari.