GitHubopen_in_new

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

The tables below are generated from source types and stay in sync with API changes.

ShowSnackbarOptions

FieldTypeRequiredDescriptionDefault
messagestring | undefinedNoSupporting text displayed inside the snackbar.-
actionSnackbarAction | undefinedNoOptional action button.-
durationnumber | null | undefinedNoMilliseconds before the snackbar closes automatically. Use `null` to disable auto close.-
timeoutValuestring | undefinedNoValue returned when the snackbar closes automatically.-
dismissValuestring | undefinedNoValue returned when the dismiss button closes the snackbar.-
positionSnackbarPosition | undefinedNoWhere the snackbar stack is placed in the viewport.-
actionOnNewLineboolean | undefinedNoWhether the action should be placed on a separate line.false
dismissibleboolean | undefinedNoWhether to show a dismiss button.false
dismissButtonLabelstring | undefinedNoAccessible label for the dismiss button."Dismiss notification"

SnackbarAction

FieldTypeRequiredDescriptionDefault
labelstringYesLabel shown in the action area.-
valuestring | undefinedNoValue returned when the action closes the snackbar.-
disabledboolean | undefinedNoWhether the action button is disabled.-
autofocusboolean | undefinedNoWhether the action button should autofocus when rendered.-
closeOnClickboolean | undefinedNoWhether clicking the action should close the snackbar.-
onClick(() => void | boolean | Promise<void | boolean>) | undefinedNoOptional callback invoked before the snackbar closes. Return `false` to keep it 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.