Skip to main content
PimentCSS v1.0.1, what's new
Home

Snackbar

Transient snackbars with actions, auto-dismiss, and progress.

Transient snackbar toasts for lightweight feedback at the edge of the viewport. Styles live in scss/components/_snackbar.scss with .progress--sm for the optional timer bar. For persistent inline messages, use Alerts; for blocking decisions, use Modals.

Semantic variants

Five surfaces aligned with the design spec: snackbar--brand, snackbar--information, snackbar--success, snackbar--warning, snackbar--error. Title color follows the variant accent; description uses text-body.

Brand

Snackbar title

Steve MacSteve, the best player for beta testing.

Link

Information

Snackbar title

Informational message for the user.

Success

Snackbar title

The operation has completed successfully.

Warning

Snackbar title

Warning: please verify the entered data.

Error

Dismissible

Always provide .snackbar__close with an accessible name. Wire dismiss with data-snackbars-live (see Behavior) or your own handler that sets hidden on the root.

Snackbar title

The operation has completed successfully.

Snackbar title

Informational message for the user.

Auto-dismiss and progress

Optional data-snackbar-auto-dismiss="{ms}" removes the snackbar after a delay. Pair with .snackbar__progress for a decorative countdown (hide the bar from assistive tech with aria-hidden="true" unless you reflect remaining time in copy).

Snackbar title

The operation has completed successfully.

Auto-hides after 6 seconds with a linear progress bar. Use the close button to dismiss immediately.

Live toast host

In apps, mount snackbars in a fixed viewport region (for example bottom-end). The demo clones a template into #pdoc-snackbar-host when you click the button.

Snackbar vs alert

  • Snackbar, short, non-blocking, often auto-dismisses; does not steal focus.
  • Alert, stays in page flow or blocks attention for important context.

Behavior in your app

Copy docs-site/src/lib/snackbar-behavior.ts and call wireAllSnackbars() after load. Handles close buttons, auto-dismiss timers (visible in viewport), progress animation, and the doc demo host.

Class reference

Class / attributeDescription
.snackbarToast container (shadow, border, max-width)
.snackbar--brand.snackbar--errorSemantic accent + progress fill tokens
.snackbar__mainIcon, body, and close button row
.snackbar__linkOptional inline action link (icon + .snackbar__link-label)
.snackbar__link-icon20px decorative icon slot (no underline on hover)
.snackbar__link-labelVisible link text (underlined on hover)
.snackbar__progressBottom .progress--sm timer bar
data-snackbars-liveWires reference dismiss / auto-dismiss script
data-snackbar-auto-dismissMilliseconds until auto-hide
data-snackbar-restoreDoc helper: show a hidden snackbar again by id

Customize (Sass)

  1. Snackbar layout

    Override width, padding, and close target before importing components.
    @use "pimentcss-design-system" with (
      $snackbar-max-width: 28rem,
      $snackbar-padding-y: 1rem,
      $snackbar-close-target: 2.75rem
    );
  2. Rebuild CSS

    Run after editing _snackbar.scss.
    npm run build:css

Accessibility (RGAA / WCAG)

Snackbars

  • Live region, use role="status" + aria-live="polite" for success/info; role="alert" + aria-live="assertive" for errors.
  • Focus, do not move keyboard focus into a snackbar unless it contains interactive controls the user must use immediately.
  • Close, the dismiss control needs aria-label (for example “Close notification”).
  • Timer, if auto-dismiss is the only indicator of remaining time, also provide text or allow users to pause/extend via the close button.
  • Viewport host, append new toasts to a single container with aria-live="polite" and aria-relevant="additions".

Next steps