Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Snackbar

Snackbar preview

Snackbar — a transient, button-triggered floating notification surface.

Public functions

Snackbar

Detailed description

A Snackbar pairs a trigger (a Button by default, or any custom widget via .trigger(...)) with a dormant content surface. Activating the trigger presents the surface as an OverlayPlacement::BottomCenter overlay and dismisses it automatically after a configurable timeout (default: 4 s). The surface stays until dismissed when .persistent() is set. Only one snackbar can be shown at a time — presenting a second one dismisses the first.

For richer, stackable, severity-aware notifications see the Toast system, which also maintains a persistent NotificationArchiveModel.

Accessibility

The content surface exposes Role::Alert with Live::Polite so screen readers announce the notification without interrupting the user. Supply .announcement(...) to give the alert a descriptive name instead of the generic "notification" fallback.

use teksilo_widgets::{Snackbar};
use teksilo_i18n::lit;
use teksilo_widgets::primitives::TextWidget;
use teksilo_tokens::TextRole;

// In build():
ctx.add(
    Snackbar::new(lit!("Undo"))
        .content(TextWidget::new(lit!("File deleted.")).color(TextRole::TooltipText))
        .announcement(lit!("File deleted."))
        .auto_dismiss_after(std::time::Duration::from_secs(5)),
);

Touch and pen

The trigger activates on the release, whether it is the default Button or a caller's widget, and the actions inside the surface are buttons and links with their own targets. Nothing here actuates on a press.

Density

The picture above is the widget at TargetDensity::Compact, the mouse-and-keyboard ladder. Below is the same subject on the same canvas with only the ladder changed, so what moves is the density and nothing else — where the subject no longer fits, that is what the denser targets cost it at that size. See docs/density-and-targets.md.

Touch

Snackbar at Touch density

API reference

📖 Full rustdoc API for this module

pub struct Snackbar

Import: use teksilo::widgets::Snackbar;

A button-triggered transient notification surface.

Call .content(...) to supply the notification body, then add the widget to the tree. The trigger label is shown as a Button (or a custom widget via .trigger(...)); activating it presents the content surface at the bottom center of the window.

#![allow(unused)]
fn main() {
pub struct Snackbar { /* fields */ }
}

Methods

pub fn new(label: impl Into<LocalizedString>) -> Self

Create a snackbar whose default trigger button shows label.

pub fn style(mut self, style: impl teksilo_core::styles::SnackbarStyle) -> Self

Per-call style override for the snackbar surface chrome. Replaces the theme-wide default SnackbarStyle for just this instance.

pub fn content(mut self, content: impl teksilo_core::IntoTeksiChild) -> Self

The snackbar body — the message (and optional inline action) shown on the floating surface.

The default surface is the high-contrast (dark) tooltip_bg, the same one tooltips use, and it stays dark in light theme. So any TextWidget you pass here must set .color(TextRole::TooltipText) (and actions can use TooltipText / TooltipShortcut) — the default TextRole::Primary is dark and renders nearly invisible on the dark surface in light theme. If you install a light-surface SnackbarStyle, color the content to match that instead.

pub fn variant(mut self, variant: ButtonVariant) -> Self

Override the default trigger ButtonVariant (default: Plain).

pub fn enabled(mut self, enabled: impl Into<Prop<bool>>) -> Self

Set the enabled state of the trigger, statically or reactively.

pub fn dismiss_behavior(mut self, dismiss: DismissBehavior) -> Self

Override the overlay dismiss behavior (default: ClickOutside).

pub fn auto_dismiss_after(mut self, duration: Duration) -> Self

Set the auto-dismiss timeout. The overlay is removed after this duration without user interaction (default: 4 s).

pub fn persistent(mut self) -> Self

Keep the snackbar visible until explicitly dismissed; disables the auto-dismiss timeout.

pub fn trigger(mut self, trigger: impl teksilo_core::IntoTeksiChild) -> Self

Replace the default Button trigger with a custom widget. The widget is wired for tap, keyboard (Enter/Space), and AT Click activation automatically.

pub fn announcement(mut self, text: impl Into<LocalizedString>) -> Self

Screen-reader announcement string — used as the Alert's accessible name when the snackbar appears. Without this the surface falls back to the generic a11y_snackbar_name i18n string, which says "notification" but can't describe the specific message. Set this whenever the snackbar conveys information the user needs to hear (errors, confirmations, status changes).