Skip to main content
Home pageComponentsSnackbar

Snackbar

A brief, non-blocking notification anchored to the bottom of the viewport. Snackbars auto-dismiss after a configurable delay and can optionally include an action button. Use them for short feedback messages — confirmations, undo prompts, or transient alerts. The auto-dismiss countdown pauses automatically while hovered or focused — including the action button itself — so an "Undo" snackbar never disappears out from under someone reaching for it, and resumes with whatever time was left once they move away.

Showing more than one at a time this way makes them overlap at the same spot. For snackbars shown imperatively from anywhere in the app (the common case — after an async action succeeds or fails), use

lt-snackbar-group instead: place one instance once, then call its show() method with a plain options object. It queues calls past max-visible instead of overlapping them, and stacks simultaneously-visible ones.

Playground​

Show snackbar
HTMLReact
ShareCopy

Usage​

<lt-snackbar id="sb">Changes saved</lt-snackbar>
<lt-button onclick="document.getElementById('sb').show()">Save</lt-button>

<lt-snackbar variant="success">Upload complete</lt-snackbar>
<lt-snackbar variant="warning">Low disk space</lt-snackbar>
<lt-snackbar variant="error">Request failed</lt-snackbar>
<lt-snackbar variant="info">Update available</lt-snackbar>

<lt-snackbar action-label="Undo">Message deleted</lt-snackbar>

<lt-snackbar duration="0" variant="warning">You are offline</lt-snackbar>

<!-- Place once; call show() from anywhere. Queues past max-visible instead of overlapping. -->

<lt-snackbar-group id="toasts" max-visible="2"></lt-snackbar-group>

<script type="module">
const toasts = document.getElementById('toasts');
document.getElementById('delete-btn').addEventListener('click', () => {
toasts.show({
message: 'File deleted',
variant: 'success',
actionLabel: 'Undo',
onAction: () => restoreFile()
});
});
</script>
import { useRef } from 'react';
import { Snackbar, Button, SnackbarGroup } from '@latty-ds/react';
import type { Snackbar as SnackbarEl, SnackbarGroup as SnackbarGroupEl } from '@latty-ds/web';

function Example() {
const ref = useRef<SnackbarEl>(null);
const toastsRef = useRef<SnackbarGroupEl>(null);
return (

<>
<Button variant="primary" onClick={() => ref.current?.show()}>Save</Button>
<Snackbar ref={ref} variant="success" actionLabel="Undo">
Changes saved
</Snackbar>

{/_ Place once; call show() from anywhere. Queues past maxVisible instead of overlapping. _/}
<SnackbarGroup ref={toastsRef} maxVisible={2} />
<Button
variant="error"
onClick={() =>
toastsRef.current?.show({
message: 'File deleted',
variant: 'success',
actionLabel: 'Undo',
onAction: () => restoreFile()
})
}

>

Delete
</Button>
</>
);
}
<script setup>import {ref} from 'vue' const snackbar = ref(null) const toasts = ref(null) function onDelete() {
toasts.value?.show({ message: 'File deleted', variant: 'success', actionLabel: 'Undo', onAction: () =>
restoreFile() }) }</script>

<template>
<lt-button variant="primary" @click="snackbar?.show()">Save</lt-button>
<lt-snackbar ref="snackbar" variant="success" action-label="Undo">
Changes saved
</lt-snackbar>

<!-- Place once; call show() from anywhere. Queues past max-visible instead of overlapping. -->

<lt-snackbar-group ref="toasts" max-visible="2"></lt-snackbar-group>
<lt-button variant="error" @click="onDelete">Delete</lt-button>

</template>

Snackbar vs. Alert​

Both communicate feedback to the user, but they serve different moments:

SnackbarAlert
PositionFixed overlay, bottom of viewportInline, within page flow
LifetimeTransient — auto-dismisses after a configurable delayPersistent — stays until dismissed or condition resolves
Use whenConfirming the result of an action the user just took (saved, deleted, copied)The message is tied to a specific location on the page (a form, a section, a card)
Avoid whenThe user needs to read and act on the message before continuingThe message is a response to a one-off action and doesn't need to persist

API — lt-snackbar​

API — lt-snackbar-group​