Toast

A brief notification that appears in a corner of the screen and goes away on its own. Use it to confirm the outcome of an action without interrupting the user; keep anything they must act on in the page.

  • vig-toaster
Import
import { Toaster, Toast } from '@vigdx/ui/toast';

Variants

Place <vig-toaster /> once in the app shell (see the app.ts tab; this site already does). Then inject the Toast service anywhere and call success() , info() , warning() or error() with a message and an optional title.

Duration

show() takes all options. duration is in milliseconds (default 5000); 0 keeps the toast until it is dismissed. Hovering a toast pauses its timer, and clear() removes every toast.

Dismiss from code

show() and the shortcuts return the toast's id; pass it to dismiss() , e.g. to replace a progress toast with the result. closable: false hides the close button.

Styling hooks

Internal elements carry a stable data-part and the component's data-scope; both are public API, so removing one is a breaking change. Select a part by both, e.g. [data-scope="toaster"][data-part="region"] { … }: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through aria-* and, where listed, a data-state; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other data-* attributes listed below (such as data-opening while an overlay animates) are API too. See Customizing.

Scope: [data-scope="toaster"]

Toaster styling hooks
Part Element data-state
region The labelled region holding the stack. —
toast One toast card around its vig-message . —
Toaster data attributes
Attribute Meaning
data-toast-id On each toast card: the id Toast.show() returned, unique while it is shown.

Accessibility

  • Toasts live in a role="region" landmark named by ariaLabel (localized “Notifications” by default), so users can find them again.
  • Each toast is announced by the toaster itself, title and message together: error and warning assertively and after their severity (“Error: …”, translatable with errorLabel and warningLabel), the other variants politely. It uses ariaNotify() where the browser has it, otherwise its own live log, which is in the page from the start and only ever gains entries, so toasts arriving together are all read (a message inserted together with its live role is not announced reliably). A toast queued behind a modal dialog is announced once the dialog closes.
  • Toasts never take focus. Hovering or keyboard focus inside a toast pauses its timer; for messages users need time to read or act on, use duration: 0 or keep the information in the page.
  • Dismissing the focused toast moves focus to the next toast, or back to where it was before entering the notifications.
  • While a modal dialog or drawer is open the page behind it is inert, so toasts raised then wait and every timer stands still; they appear once the last modal closes.
  • Close buttons are named by closeAriaLabel on the toaster (localized “Dismiss” by default).

API

Toaster

vig-toaster component

Host for the Toast service — place once in the app shell. Each toast renders as a vig-message on an opaque card. A message inserted together with its live role is not announced reliably, so the toaster announces each new toast itself, errors and warnings assertively and after their severity (errorLabel, warningLabel: "Error: …"), the rest politely: through ariaNotify() where supported, otherwise by adding an entry to its own live log, which is in the page from the start. Entries are added, never replaced, so toasts that arrive together are all read, and the log is apart from the shared announcer that form errors use. Hover and keyboard focus pause a toast; dismissing the focused toast moves focus to the next one, or back to where it was before entering the region. A stack taller than the viewport scrolls, and the region then joins the tab order so keyboard users can scroll it. Each toast card carries data-toast-id, unique while it is shown. data-toast-id

Toaster props
Name Type Default Description
ariaLabelstring | undefinedundefined
—
closeAriaLabelstring | undefinedundefined
—
errorLabelstring | undefinedundefined

Spoken before error toasts (i18n); defaults to toastErrorLabel.

positionToasterPosition'top-right'

Where the stack sits. The default is the physical top right corner (as in 2.0, until 3.0); prefer top-end, which follows the text direction.

warningLabelstring | undefinedundefined

Spoken before warning toasts (i18n); defaults to toastWarningLabel.

Toast

injectable

Imperative notifications (PrimeNG MessageService territory): place once in the app shell, then toast.success('Saved'). Hovering or focusing a toast pauses its timer; leaving restarts the full delay.

While a modal vig-dialog / vig-drawer is open the page behind it is inert, so a toast there could be neither read nor dismissed: new toasts queue up and every timer stands still until the last modal closes.

Toast methods
Signature Description
clear(): void
—
dismiss(id: number): void
—
error(message: string, title?: string): number
—
info(message: string, title?: string): number
—
pause(id: number): void

Stops the auto-dismiss timer (used while hovered or focused).

resume(id: number): void

Restarts the full auto-dismiss delay (deferred while a modal is open).

show(options: ToastOptions): number
—
success(message: string, title?: string): number
—
warning(message: string, title?: string): number
—

Are you sure?