Mushilu-San UI

Search components

PlaygroundStorybookGitHub
Feedback

Toast

A short, temporary message that appears at the edge of the screen and dismisses itself.

Selector: mui-toast-container

Import
import { Toast, ToastContainer, ToastService } from '@mushilu-san/ui/feedback';
PreviewCode

Loading example…

Overview

Add one mui-toast-container to the app, then call ToastService from anywhere to show a toast. info, success, warning and danger set the variant, and duration sets how long it stays (0 keeps it until dismissed).

Hovering or focusing a toast pauses its timer. Info and success toasts are announced politely. Warning and danger toasts are announced assertively.

When to use

  • Confirming an action that does not need a response, such as "Link copied".
  • Reporting a background result the user does not have to act on.

When not to use

  • A message the user must read before continuing. Use an alert or dialog. Use Alert instead.
  • An error that belongs to one field. Show it next to the field. Use Form field instead.

Guidelines

Do

  • Keep the message to one short sentence.
  • Offer an action in the toast only when it saves the user effort.

Don't

  • Do not show toasts for errors the user must fix.
  • Do not stack many toasts. Show the latest result.

Accessibility

Roles and attributes

ElementRoleNotes
containerregionaria-label from label, default "Notifications". A polite and an assertive live region; warning and danger use the assertive one.
toast—Announced through the live region, not focused.

Keyboard

KeysAction
TabShiftTabMoves focus to a toast dismiss button when one is shown.
  • Do not rely on a toast for information that must stay on screen. Keep the result on the page too.

API

Toast

Selector: mui-toast

NameTypeDefaultDescription
variant'info' | 'danger' | 'success' | 'warning''info' Meaning of the toast: `info`, `success`, `warning` or `danger`. Default `info`.
messagestring'' Body text of the toast.
headingstring | undefined— Optional short heading above the message.
durationnumber5000 ms before auto-dismiss; 0 disables the timer.
NameTypeDescription
dismissedvoid Emits when the toast is dismissed, by timer or by the user.

CSS parts

  • ::part(dismiss)
  • ::part(message)
  • ::part(root)
  • ::part(title)

ToastContainer

Selector: mui-toast-container

NameTypeDefaultDescription
placement'top-start' | 'top-center' | 'top-end' | 'bottom-start' | 'bottom-center' | 'bottom-end''bottom-end' Where toasts appear on screen. Default `bottom-end`.
labelstring'Notifications' Accessible name for the notifications landmark.

CSS parts

  • ::part(root)

ToastService

Service, provided in root

MethodSignatureDescription
show(message: string, options?: ToastOptions): ToastRef
info(message: string, options?: Omit<ToastOptions, "variant"> | undefined): ToastRef
success(message: string, options?: Omit<ToastOptions, "variant"> | undefined): ToastRef
warning(message: string, options?: Omit<ToastOptions, "variant"> | undefined): ToastRef
danger(message: string, options?: Omit<ToastOptions, "variant"> | undefined): ToastRef
dismiss(id: number): void
clear(): void

Tokens

  • --mui-color-surface-raised
  • --mui-color-border
  • --mui-shadow-4
  • --mui-z-toast
  • --mui-color-focus-ring