No results found

Toast

Displays brief, temporary notifications that automatically disappear after a set time.

Operation completed successfully!

Features

  • Multiple toast positioning options
  • Configurable auto-dismiss duration
  • Controlled & uncontrolled state management
  • Animation states (visible/hidden)
  • Multiple simultaneous toasts support
  • Custom styling per position
  • Manual or automatic toast dismissal
  • Unique toast identification
  • Signal-based state binding
  • Automatic timeout cleanup

Anatomy

PartDescription
<Toast.Root>A root component that manages toast state, positioning, and duration
<Toast.Content>A content component that displays the toast message or elements

Examples

Basic Usage

The toast component can be implemented with minimal configuration using the position and duration props. The position prop determines where the toast appears on screen, while duration sets how long it remains visible.

Operation completed successfully!

In this example, we use:

Visual Features

Toast Positioning

Toasts can be positioned in six different locations on the screen using the position prop:

Each position value affects where the toast appears relative to the viewport edges.

Advanced Usage

Multiple Toasts

Multiple toasts can be displayed simultaneously, each with its own position and timing. Each toast operates independently and can be controlled separately.

Component State

Using Component State

The Toast component's state can be controlled in two primary ways:

  1. Uncontrolled State Use the open prop to set the initial visibility state of the toast:
<Toast.Root open={false}>
  <Toast.Content>Message</Toast.Content>
</Toast.Root>
  1. Controlled State For reactive control, use the bind:open prop with a boolean signal: As shown in the hero example, you can control the toast's visibility state and respond to changes: The example demonstrates:

State Interactions

The toast component provides several ways to interact with its state:

  1. Automatic Dismissal By default, toasts automatically dismiss after the specified duration. As shown in the hero example, setting duration={5000} will close the toast after 5 seconds.
  2. Manual Control You can manually control the toast's visibility:
<button onClick$={() => (isOpen.value = true)}>Show</button>
<button onClick$={() => (isOpen.value = false)}>Hide</button>
<Toast.Root bind:open={isOpen}>
  <Toast.Content>Controlled toast</Toast.Content>
</Toast.Root>
  1. Multiple Toast Management As demonstrated in the hero example, multiple toasts can be managed independently:

Based on the provided implementation and examples, I'll document the Toast configuration options.

Core Configuration

Positioning

The Toast component supports six positioning options through the position prop on Toast.Root:

As shown in the hero example above, the position can be set using the position prop:

type ToastPosition =
  | "top-left"
  | "top-right"
  | "bottom-left"
  | "bottom-right"
  | "top-center"
  | "bottom-center";

Duration

The duration prop controls how long the toast remains visible before automatically closing. The default duration is 5000 milliseconds (5 seconds).

State Management

The Toast component supports both controlled and uncontrolled state management:

  1. Uncontrolled: Use the open prop for initial state
  2. Controlled: Use the bind:open prop with a signal

Note: When using bind:open, the duration timer will automatically clean up if the component unmounts.

Advanced Configuration

Multiple Toasts

The Toast system supports multiple simultaneous toasts, each requiring a unique id. When not provided, an ID is automatically generated using crypto.randomUUID(). As shown in the hero example above, each toast operates independently with its own:

Technical Constraints

  1. Positioning: Toast positions are fixed relative to the viewport
  2. Stacking: Multiple toasts in the same position stack in order of appearance
  3. Animation: State changes trigger CSS transitions via the data-state attribute
  4. Cleanup: Timeout handlers are automatically cleaned up on:
    • Component unmount
    • Duration changes
    • Manual close events

API Reference

Toast Root

Inherits from: <div />

Props

PropTypeDefaultDescription
"data-qds-toast-root"boolean-
"data-position"ToastPosition-
"data-state""visible" | "hidden"-

Data Attributes

AttributeDescription
data-position
data-state

Toast Content

Inherits from: <div />

Data Attributes

AttributeDescription
data-stateIndicates the visibility state of the toast content (visible or hidden)

Accessibility

Keyboard Interactions

KeyDescription
TabWhen the toast is open, moves focus to the next focusable element within the toast
Shift+TabWhen the toast is open, moves focus to the previous focusable element within the toast