toast-msg

Non-modal notifications with auto-dismiss, variants, action buttons, and configurable positioning.

Overview

The <toast-msg> component is a container for displaying toast notifications. Toasts appear in a fixed position and automatically dismiss after a configurable duration.

Attributes

AttributeValuesDefaultDescription
position"top-start", "top-center", "top-end", "bottom-start", "bottom-center", "bottom-end"Screen position for the toast stack
durationnumberDefault auto-dismiss duration in milliseconds
maxnumberMaximum number of visible toasts

Variants

Toasts support four variants for different types of messages.

Action Buttons

Toasts can include an action button for user interaction.

Duration Control

Control how long toasts remain visible before auto-dismissing.

JavaScript API

show(options)

Display a toast notification.

Option Type Default Description
message string - The message to display (required).
variant string "info" Toast variant: info, success, warning, error.
duration number 5000 Auto-dismiss duration in ms. Set to 0 to disable.
dismissible boolean true Whether to show a dismiss button.
action string - Optional action button text.
onAction function - Callback when action button is clicked.

dismissAll()

Dismiss all visible toasts and clear the queue.

Events

The component dispatches events when toasts are shown or hidden.

Event Detail Description
toast-msg:show { toast: HTMLElement } Fired when a toast is displayed.
toast-msg:hide { toast: HTMLElement } Fired when a toast is dismissed.

Accessibility

ARIA Attributes

  • The toast container has role="region" and aria-label="Notifications"
  • The container has aria-live="polite" so new toasts are announced
  • Each toast has role="alert"

Screen Reader Behavior

When a toast appears, screen readers announce its content. The aria-live="polite" setting ensures announcements don't interrupt the user.

Best Practices

  • Keep toast messages brief and actionable
  • Don't use toasts for critical information that requires action
  • Provide sufficient time for users to read the message
  • Use appropriate variants to convey message type
  • Ensure dismiss buttons are accessible via keyboard

Common Patterns

Form Submission Feedback

Async Operation Feedback

Connection Status