NbToast renders a single message and stays exactly what it was. NbToaster decides when it appears and when it goes.
Why this is library code now
A host over NbToast has several parts that are easy to lose without noticing, and each one fails silently:
- without auto-dismiss, successes accumulate for the life of the route,
var(--nb-z-toast)is a name that does not exist, so a host that writes it runs on the fallback rather than--nb-zindex-toast,- without
role="alert", the variant icon, the action and pause-on-hover, the message loses its announcement, its severity cue and its undo.
That is what a container costs to get right, so the library provides it.
When to toast
A toast is news that expires. If the message would still be true and still be worth reading five minutes from now, it is not a toast.
| Use | When |
|---|---|
NbToaster | Something just finished, anywhere on the page, and the news self-clears. |
NbBanner | Something is true about this page or task and stays on screen. |
NbMessage | One field has something to say about its own value. |
NbConfirm | Nothing else may proceed until the user answers. |
| Notification centre | The news outlives the moment and has to be findable later. |
Do not toast a validation error: it belongs next to the field that caused it. Do not toast something the user can already see happening. Do not toast twice for one action.
The row above is the surface. Which words a state is allowed to be called, and which component owns "what is true about this thing right now", are settled once in Status indicators rather than restated here. A toast is the only entry in that vocabulary that is a change rather than a state, which is exactly why it may expire and the others may not.
Live demo
The stack below is the real component. It is teleported into the framed area rather than to <body>, so it stays inside the page: the toaster is position: fixed, and a transform on an ancestor is what makes fixed positioning resolve against that ancestor instead of the viewport. In an application you leave to alone and the stack anchors to the viewport corner.
Hover it, tab into it, press Alt + T, and watch the countdown bars stop. "Route change" runs what a router guard would run: everything goes except the retained toast.
The clock is shared
The whole region pauses, not the toast under the pointer. Pausing only the hovered one lets the two below it expire while they are being read, which is the bug that makes people distrust toasts.
The clock is held while:
- the pointer is over the stack,
- focus is anywhere inside it,
- the browser tab is hidden.
It resumes from the time that was left, never from the beginning. That is why every expiring toast carries a hairline countdown at its bottom edge: it is the only visible statement of how long is left, and it stops where the clock stops.
Writing the message
Say what happened, in the past tense, without a full stop. Put anything the user has to do in a title and keep the message to the recovery.
| Do | Don't |
|---|---|
toast.success('Draft saved') | toast.success('Success!') |
toast.error('Could not reach the server', { title: 'Save failed' }) | toast.error('Something went wrong. Please try again.') |
cta: { label: 'Try again', ... } | cta: { label: 'OK', ... } |
| One toast per action | One toast for the request and another for the response |
Tense, capitalisation and the sentence shapes are not this component's to decide: Writing style is the source, and this section only adds what is peculiar to a message that removes itself.
Label the action with its verb from Action labels: Try again, Refresh, Undo. Cancel, Done, Close and Dismiss get used interchangeably for leaving, so a toast's action should never be one of them: the close button is the exit, and a second control that also means "go away" is a coin toss for anyone reading the stack through a screen reader.
Replacing a hand-built host
If your application has its own toaster over NbToast, the move is mechanical:
- Delete the local
Toaster.vueand the localuseToast. Mount<NbToaster />in its place. - Rename the push call:
push({ variant: 'success', message })becomestoast.success(message).pushstill exists with the same option names. - Delete any local
z-indexrule. The host sets--nb-zindex-toast, which resolves above modals. If you had--nb-z-toast, that name never existed. - Anywhere you raised two toasts for one operation (a "saving" and then a "saved"), keep the handle from the first and
update()it.
What changed in NbToast
The API is backwards compatible: a bare <NbToast> still times itself, still pauses under the pointer, and still defaults to role="alert". role and closeLabel became real props with their old values as defaults, and managed, paused and cycle are additive.
One change is visible to consuming code, and it is the reason this section exists. Every NbToast now renders a visually hidden severity word before the title, so a screen reader hears "Error. Could not reach the server" rather than a sentence whose severity was only ever a colour and an aria-hidden icon. That changes the accessible text of every existing standalone toast, and with it wrapper.text() in your tests and any snapshot that covers one.
- If the word is wanted, which it usually is, update the assertion.
- If your title already carries it ("Save failed"), pass
status-label=""to suppress it and avoid "Error. Save failed. Could not reach the server". - Under
NbToasteryou do not need to do anything: the host passes the queue'sstatusLabels, and translates them with the rest of the interface.
The info variant's icon and left rule also move from the brand purple (--nb-c-primary) to --nb-c-info, the same token NbBanner uses, and the corner radius moves from a hardcoded 10px to --nb-radius-md.