Snackbar Group
lt-snackbar-group is the recommended way to show snackbars from anywhere in an app. Place
one instance at the end of your page and call its show() method whenever you need a
notification. It handles queuing, stacking, and top-layer positioning automatically.
See the Snackbar page for the individual snackbar API and a
comparison with lt-alert.
How it works
- Calls to
show()create managedlt-snackbarinstances inside the group. - Up to
maxVisiblesnackbars display simultaneously, stacked vertically. - Extra calls queue automatically and are presented as earlier ones dismiss.
- The group renders as a native manual popover in the top layer, so notifications appear above dialogs and side panels regardless of z-index.
- The auto-dismiss countdown pauses while a snackbar is hovered or focused, then resumes with whatever time was left.
Usage
<lt-snackbar-group id="notifications"></lt-snackbar-group>
<lt-button onclick="showSnackbar()">Show notification</lt-button>
<script type="module">
function showSnackbar() {
const group = document.querySelector('#notifications');
group.show({
message: 'Changes saved',
variant: 'success',
});
}
window.showSnackbar = showSnackbar;
</script>
import { useRef } from 'react';
import { SnackbarGroup, Button } from '@latty-ds/react';
export function Notifications() {
const ref = useRef(null);
return (
<>
<SnackbarGroup ref={ref} />
<Button onClick={() => ref.current?.show({
message: 'Changes saved',
variant: 'success',
})}>
Show notification
</Button>
</>
);
}
<template>
<lt-snackbar-group ref="notifications"></lt-snackbar-group>
<lt-button @click="showSnackbar">Show notification</lt-button>
</template>
<script setup>
import { ref } from 'vue';
const notifications = ref(null);
function showSnackbar() {
notifications.value?.show({ message: 'Changes saved', variant: 'success' });
}
</script>
Action button and undo pattern
Pass actionLabel and onAction to add an action button. The callback fires once
when clicked, then the snackbar dismisses itself.
<script type="module">
document.getElementById('notifications').show({
message: 'File deleted',
variant: 'error',
actionLabel: 'Undo',
duration: 6000,
onAction: () => restoreFile(),
});
</script>
Stacking multiple snackbars
Set max-visible to show more than one at a time. Calls past the limit queue until a
slot opens.
<lt-snackbar-group id="toasts" max-visible="3"></lt-snackbar-group>
Internationalization
Pass labels to override the dismiss button's accessible name for non-English UIs.
group.show({
message: 'Cambios guardados',
variant: 'success',
labels: { dismiss: 'Cerrar' },
});
When to use a standalone snackbar instead
If your app only ever shows one snackbar at a time from a single place (for example a form
submission handler), a standalone lt-snackbar with a direct show() call
works fine. Reach for lt-snackbar-group when notifications can come from multiple
parts of the app or might overlap.