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.
<div class="snackbar snackbar--success" role="status" aria-live="polite">
<div class="snackbar__main">
<span class="snackbar__icon" aria-hidden="true"></span>
<div class="snackbar__body">
<div class="snackbar__text">
<p class="snackbar__title">Saved</p>
<p class="snackbar__description">Your changes were stored.</p>
</div>
</div>
<button type="button" class="snackbar__close" aria-label="Close">×</button>
</div>
</div>
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.
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).
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.
import { wireAllSnackbars } from './snackbar-behavior';
document.addEventListener('DOMContentLoaded', () => wireAllSnackbars());
Class reference
| Class / attribute | Description |
|---|---|
.snackbar | Toast container (shadow, border, max-width) |
.snackbar--brand … .snackbar--error | Semantic accent + progress fill tokens |
.snackbar__main | Icon, body, and close button row |
.snackbar__link | Optional inline action link (icon + .snackbar__link-label) |
.snackbar__link-icon | 20px decorative icon slot (no underline on hover) |
.snackbar__link-label | Visible link text (underlined on hover) |
.snackbar__progress | Bottom .progress--sm timer bar |
data-snackbars-live | Wires reference dismiss / auto-dismiss script |
data-snackbar-auto-dismiss | Milliseconds until auto-hide |
data-snackbar-restore | Doc helper: show a hidden snackbar again by id |
Customize (Sass)
-
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 ); -
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"andaria-relevant="additions".