Skip to content

GkSnackbar

A non-blocking message surface teleported to body: no scrim, Escape closes, auto-dismiss via timeout, pause while hovered or focused (timer and countdown reset on resume, matching common snackbar behavior). location controls edge and alignment (e.g. bottom center, top start). timer adds a thin linear countdown strip.

For imperative messages from arbitrary code, add GkSnackbarHost once (e.g. in App.vue) and call pushGkSnackbar({ text, ... }) from useGkSnackbar / pushGkSnackbar.

When to use

Use for transient, non-blocking status updates after user actions (save complete, retry warning, background sync status).

Live demo

API — GkSnackbar

Props

PropTypeDefaultDescription
modelValuebooleanfalseOpen state; v-model
title / textstringText content (also #title / #text slots)
timeoutnumber | string5000Auto-close ms; -1 = no auto-close
timerboolean | 'top' | 'bottom'falseCountdown strip position
timerColorstringStrip color (CSS)
reverseTimerbooleanfalseStrip fills from the opposite side
variant'neutral' | 'info' | ...'neutral'Surface tone (aligned with GkAlert)
locationstring'bottom center'Edge + alignment, e.g. bottom start, left center
roundedbooleantrueRounded corners
elevation05Shadow preset
loadingbooleanfalseShows GkSpinner in prepend when no #prepend
prependAvatar / prependIconstringImage URL or short glyph
verticalbooleanfalseStack content vertically
collapsed{ width, height }Fixed dimensions (CSS variables)
queueIndex / queueGapnumber0 / 8Stacking offset for GkSnackbarHost
zIndexnumber | stringtokenLayering
tostring | HTMLElement'body'Teleport target
transitionNamestring'gk-snackbar'Vue <Transition> name

Slots

SlotSlot propsDescription
defaultMain body
headerAbove the row
prependReplaces default prepend media
title / textOverrides title / text props
actionsisActiveAction buttons (GkButton recommended); isActive is the v-model ref

Events

EventDescription
update:modelValueOpen state
afterEnter / afterLeaveTransition hooks

Programmatic API

  1. Mount GkSnackbarHost once in your app root.
  2. Call pushGkSnackbar({ text: '…', variant: 'success', timeout: 4000 }) from anywhere (or useGkSnackbar().push).
  3. Returns { id, dismiss }dismiss() closes that item after its leave transition.

clearGkSnackbars() removes all queued items immediately (no leave animation).

Tokens

TokenPurpose
--gk-snackbar-z-indexStacking
--gk-snackbar-insetEdge padding
--gk-snackbar-max-widthPanel width cap
--gk-snackbar-stack-unitApproximate height for stacked offsets

Examples

Basic

vue
<GkSnackbar v-model="open" text="Saved successfully." :timeout="3000" />

Advanced

vue
<GkSnackbar
  v-model="open"
  title="Deployment started"
  text="We will notify you when the rollout finishes."
  timer="bottom"
  location="top end"
  variant="info"
/>

Edge case

vue
<GkSnackbar v-model="open" :timeout="-1" variant="danger">
  <template #actions="{ isActive }">
    <GkButton size="sm" variant="secondary" @click="isActive = false">Dismiss</GkButton>
  </template>
</GkSnackbar>

Accessibility notes

  • Keep snackbar text concise and action-oriented; avoid long instructional content.
  • Provide explicit action labels in #actions slots.
  • Use indefinite timeout (-1) only when users must manually acknowledge the message.

Released under the MIT License.