showSnackbar

showSnackbar() is the programmatic entry point for transient notifications. It renders a snackbar into the shared stack, waits for it to close, and resolves with the outcome.

Basic Usage

ts
import { showSnackbar } from '@rikkaw/m3-vue';

await showSnackbar({
  message: 'Saved',
});

Return Value

The promise resolves when the snackbar closes.

  • Action click resolves to action.value, or 'action' by default.
  • Dismiss button resolves to dismissValue, or 'dismiss' by default.
  • Auto timeout resolves to timeoutValue, or 'timeout' by default.

The promise rejects if the function is called outside a browser environment, or if action.onClick throws or rejects.

Options

FieldTypeDefaultNotes
messagestring''Snackbar text content
actionSnackbarAction-Optional action button
durationnumber | null4000Auto-close delay in milliseconds, or null to disable it
timeoutValuestring'timeout'Value resolved on auto close
dismissValuestring'dismiss'Value resolved on dismiss button click
position'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end''bottom'Snackbar stack placement
actionOnNewLinebooleanfalsePassed through to the Snackbar component
dismissiblebooleanfalseShows the dismiss button
dismissButtonLabelstring'Dismiss notification'Accessible label for the dismiss button

SnackbarAction fields:

FieldTypeDefaultNotes
labelstring-Visible label
valuestring'action'Resolution value when the action closes the snackbar
disabledbooleanfalseDisables the action button
autofocusbooleanfalseAutofocuses the action button
closeOnClickbooleantrueKeep the snackbar open by setting this to false
onClick() => void | boolean | Promise<void | boolean>-Return false to keep the snackbar open

Behavior Notes

  • Multiple snackbars can be shown at the same time.
  • Stacks are separated by position, so top and bottom placements do not interfere with each other.
  • Hovering or focusing the snackbar pauses the auto-close timer.
  • Leaving the snackbar resumes the remaining time instead of restarting the full duration.

For manually rendered snackbars, see Snackbar.