navius

Toast

A succinct message that is displayed temporarily.

    Features

    • Automatically closes on a timer that pauses on hover, focus, and window blur, then resumes.
    • Swipe to dismiss, with a configurable SwipeDirection and SwipeThreshold.
    • Can be controlled (@bind-Open) or uncontrolled (DefaultOpen).
    • Announces to assistive technology via polite or assertive live regions, by toast Type.
    • A global hotkey (default F8) jumps focus to the viewport from anywhere on the page.
    • Exposes a discrete data-open / data-closed contract plus swipe CSS variables for enter, exit, and swipe animations.

    Installation

    Install the brain, or copy just this primitive in with the CLI.

    Anatomy

    Import the parts and assemble them.

    API Reference

    Cascades configuration (duration, label, swipe) to every descendant toast and viewport, and owns the shared announcer. Renders no DOM of its own.

    Prop Type Default
    Manager ToastManager? -
    Limit int 1
    Timeout int 5000
    Label string "Notification"
    SwipeDirection string "right"
    SwipeThreshold double 50
    ChildContent RenderFragment? -

    The fixed region that hosts the live toasts. Renders an ol with role=region, plus the visually-hidden live announcer regions.

    Prop Type Default
    Hotkey string[] [ "F8" ]
    LabelTemplate Func<string, string, string>? -
    ChildContent RenderFragment? -
    Data attribute Values
    [data-navius-toast-viewport] Present on the viewport region

    A single toast. Owns the open lifecycle, the auto-close timer, and the swipe gesture. Renders an li.

    Prop Type Default
    Toast ToastObject? -
    Open bool true
    OpenChanged EventCallback<bool> -
    DefaultOpen bool true
    ForceMount bool false
    Timeout int? -
    Priority string "low"
    Type string? -
    OnEscapeKeyDown EventCallback<NaviusEscapeKeyDownEventArgs> -
    OnSwipeStart EventCallback -
    OnSwipeMove EventCallback<(double X, double Y)> -
    OnSwipeEnd EventCallback<(double X, double Y)> -
    OnSwipeCancel EventCallback -
    OnPause EventCallback -
    OnResume EventCallback -
    ChildContent RenderFragment? -
    Data attribute Values
    [data-open] Present while the toast is open
    [data-closed] Present while the toast is closed
    [data-swipe-direction] "right" | "left" | "up" | "down"
    [data-swiping] Present during a swipe
    [data-limited] Present while queued beyond the visible limit

    During a swipe the engine writes --toast-swipe-movement-x and --toast-swipe-movement-y (px) on the root so CSS transforms can follow the pointer.

    The toast's title. Carries the id referenced by the Root's aria-labelledby. Renders a div.

    Prop Type Default
    ChildContent RenderFragment? -
    Data attribute Values
    [data-navius-toast-title] Present on the title element

    The toast's description. Carries the id referenced by the Root's aria-describedby. Renders a div.

    Prop Type Default
    ChildContent RenderFragment? -
    Data attribute Values
    [data-navius-toast-description] Present on the description element

    An actionable button inside a toast (e.g. Undo). Activating it closes the toast. AltText is required for assistive tech. Renders a button.

    Prop Type Default
    AltText string ""
    OnClick EventCallback -
    ChildContent RenderFragment? -
    Data attribute Values
    [data-navius-toast-action] Present on the action button

    A composable close button that dismisses the toast on click. Renders a button.

    Prop Type Default
    ChildContent RenderFragment? -
    Data attribute Values
    [data-navius-toast-close] Present on the close button

    Accessibility

    Adheres to the alert WAI-ARIA design pattern. A foreground toast renders role="alert" (assertive); a background toast renders role="status" (polite). Title and Description supply aria-labelledby and aria-describedby.

    Key Description
    F8 Moves focus to the viewport, so the toasts and their buttons can be reached. Configurable via Hotkey.
    Tab Moves focus through the focusable elements inside the focused toast (its action and close buttons).
    Space When focus is on an Action or Close button, activates it and dismisses the toast.
    Enter When focus is on an Action or Close button, activates it and dismisses the toast.
    Escape Closes the focused toast, unless prevented in OnEscapeKeyDown.