Create

Feedback

Toast

Copy page View as Markdown Open in ChatGPT Open in Claude

A succinct message that is displayed temporarily.

Usage#

app.component.ts
import { WdsToasterComponent } from '@wds/angular/toast';

Examples#

Default#

toast() shows a notification and returns its id. It uses the <wds-toaster> on the page, or adds one when there is none; in an app, put one <wds-toaster> in the root layout. In Angular import toast from @wds/angular/toast, elsewhere from @wds/core/toast.

Show toast

Types#

toast.success, info, warning, error and loading add an icon. toast.promise shows a loading toast that turns into success or error when the promise settles.

DefaultSuccessInfoWarningErrorPromise

Action and cancel#

action and cancel add buttons; both close the toast unless onClick calls event.preventDefault(). duration sets the time in ms.

Delete fileInvitation

Update and dismiss#

A toast with an existing id updates that toast. duration: Infinity keeps it until it is closed; toast.dismiss(id) closes one toast and toast.dismiss() all of them.

Upload fileNo time limitDismiss all

Position#

position places the toaster in a corner or at the center of an edge. A toaster with an id gets only the toasts whose toaster option names it, so it can sit next to the default one; give it its own label.

top-lefttop-centertop-rightbottom-leftbottom-centerbottom-right

Options#

rich-colors colors success, info, warning and error toasts; expand keeps the stack expanded; hide-close hides the close button (a swipe still closes the toast).

Rich colorsExpandHide close
SuccessError

API References#

wds-toaster#

The place where notifications appear. The toast() function adds them. The stack expands on hover and focus, alt+T moves focus to the notifications, and a swipe closes a toast. The timer pauses while the user interacts with them. It is shown in the top layer, above lists and menus.

Attributes

AttributeTypeDefaultDescription
positionWdsToasterPosition'bottom-right'Position on the screen.
expandbooleanfalseKeeps the stack expanded (toasts do not overlap).
rich-colors.richColorsbooleanfalseColored background for success, info, warning and error toasts.
hide-close.hideClosebooleanfalseHides the close button (a toast still closes with a swipe and after its duration).
durationnumber4000Default duration in ms.
visible-toasts.visibleToastsnumber3How many toasts are visible at once.
gapnumber12Gap between toasts in the expanded stack (px).
labelstring'Powiadomienia'Accessible name of the region.
close-label.closeLabelstring'Zamknij powiadomienie'Label of the close button.

Methods

MethodDescription
add(toast: WdsToast)Adds a toast, or updates the one with the same id. Usually called by toast().
dismiss(id?: string | number)Closes the toast with the given id, or all toasts.

CSS parts (::part)

PartDescription
listThe list of toasts.
toastA single toast.
closeThe close button.

CSS custom properties

PropertyDescription
--wds-toaster-widthWidth of a toast (default 24rem).
--wds-toaster-offsetDistance from the edge of the window (default 16px).

Accessibility#

Screen reader#

The toaster is a region named by label (default Powiadomienia, in Polish) with a hint about alt+T. It exists before the first toast, so screen readers announce new toasts.

Each toast has role="status" (announced politely) or, for toast.error, role="alert" (announced at once); aria-atomic reads the title and the description together. Icons are hidden from screen readers.

Action and cancel are native buttons named by their label. The close button is named by close-label (default Zamknij powiadomienie, in Polish).

The timer pauses while the pointer is over the stack or focus is inside it, so there is time to read and use the buttons. Do not put the only way to do something in a toast: it disappears.

Keyboard support#

KeyFunction
Alt + TMoves focus to the newest toast.
TabMoves between toasts and their buttons.
EnterSpaceActivates the focused button.
EscapeLeaves the toasts; the timer runs again.
Footer