Keyboard shortcut: Ctrl + K
Get started

Snackbar

Call snackbar() to confirm an action through VSnackbar, with an optional follow-up button. A new message replaces the previous one.

Usage

vue
<script setup lang="ts">
import { VButton, snackbar } from 'vectis-ui'

function remove() {
  snackbar({ message: 'Message deleted.', actionText: 'Undo', action: () => {} })
}
</script>

<template>
  <!-- Mount VSnackbar once in your application. This site already provides it. -->
  <VButton variant="outline" tone="neutral" @click="remove">Delete</VButton>
</template>

Examples

Tones

Choose neutral or danger tone. Both use solid styling.

vue
<script setup lang="ts">
import { VButton, snackbar } from 'vectis-ui'
</script>

<template>
  <div class="demo">
    <VButton
      variant="outline"
      tone="neutral"
      @click="snackbar({ message: 'Conversation archived.', action: () => {} })"
    >
      Archive
    </VButton>

    <VButton
      variant="outline"
      tone="danger"
      @click="
        snackbar({
          tone: 'danger',
          message: 'Could not save your changes.',
          actionText: 'Retry',
          action: () => {},
        })
      "
    >
      Failing action
    </VButton>
  </div>
</template>

<style scoped>
.demo {
  display: flex;
  flex-wrap: wrap;
  gap: var(--vectis-space-3);
}
</style>

Without an action

Without an action, no button appears. Running an action dismisses the bar.

vue
<script setup lang="ts">
import { VButton, snackbar } from 'vectis-ui'
</script>

<template>
  <VButton variant="outline" tone="neutral" @click="snackbar({ message: 'Settings saved.' })">
    Save
  </VButton>
</template>

With an icon

icon adds an optional icon. The tone provides none by default.

vue
<script setup lang="ts">
import { VButton, snackbar } from 'vectis-ui'
import { cloud_upload as cloudUpload } from 'vectis-ui/icons'
</script>

<template>
  <VButton
    variant="outline"
    tone="neutral"
    @click="snackbar({ message: 'File uploaded.', icon: cloudUpload, action: () => {} })"
  >
    Upload
  </VButton>
</template>

Placements

Choose bottom start, centre or end. Set the default on VSnackbar or override it per message.

vue
<script setup lang="ts">
import { VButton, snackbar, type SnackbarPlacement } from 'vectis-ui'

const placements: SnackbarPlacement[] = ['bottom-left', 'bottom-center', 'bottom-right']
</script>

<template>
  <div class="demo">
    <VButton
      v-for="placement in placements"
      :key="placement"
      variant="outline"
      tone="neutral"
      @click="snackbar({ placement, message: `Raised at ${placement}.`, action: () => {} })"
    >
      {{ placement }}
    </VButton>
  </div>
</template>

<style scoped>
.demo {
  display: flex;
  flex-wrap: wrap;
  gap: var(--vectis-space-3);
}
</style>

One at a time

A new message replaces the visible one and restarts its timer.

vue
<script setup lang="ts">
import { VButton, snackbar } from 'vectis-ui'
</script>

<template>
  <div class="demo">
    <VButton
      variant="outline"
      tone="neutral"
      @click="snackbar({ message: 'Message deleted.', duration: 0, action: () => {} })"
    >
      Delete
    </VButton>

    <VButton
      variant="outline"
      tone="neutral"
      @click="snackbar({ message: 'Conversation archived.', duration: 0, action: () => {} })"
    >
      Archive
    </VButton>
  </div>
</template>

<style scoped>
.demo {
  display: flex;
  flex-wrap: wrap;
  gap: var(--vectis-space-3);
}
</style>

How long it stays

duration sets the lifetime in milliseconds. The timer pauses while the pointer or keyboard focus is inside the bar.

vue
<script setup lang="ts">
import { VButton, snackbar } from 'vectis-ui'
</script>

<template>
  <div class="demo">
    <VButton
      variant="outline"
      tone="neutral"
      @click="snackbar({ message: 'Gone in 1.5 seconds.', duration: 1500, action: () => {} })"
    >
      1.5 seconds
    </VButton>

    <VButton
      variant="outline"
      tone="neutral"
      @click="snackbar({ message: 'Gone in 8 seconds.', duration: 8000, action: () => {} })"
    >
      8 seconds
    </VButton>
  </div>
</template>

<style scoped>
.demo {
  display: flex;
  flex-wrap: wrap;
  gap: var(--vectis-space-3);
}
</style>

Keeping it until it is taken away

duration: 0 keeps the bar open. Use the ID returned by snackbar() with dismissSnackbar() to close it.

vue
<script setup lang="ts">
import { ref } from 'vue'
import { VButton, dismissSnackbar, snackbar } from 'vectis-ui'

const id = ref<number | null>(null)

function raise() {
  // A stale ID cannot dismiss a replacement message.
  id.value = snackbar({ message: 'Stays until you take it away.', duration: 0 })
}
</script>

<template>
  <div class="demo">
    <VButton variant="outline" tone="neutral" @click="raise">Raise</VButton>

    <VButton variant="outline" tone="neutral" @click="dismissSnackbar(id ?? undefined)">
      Dismiss
    </VButton>
  </div>
</template>

<style scoped>
.demo {
  display: flex;
  flex-wrap: wrap;
  gap: var(--vectis-space-3);
}
</style>

API

Props

PropTypeDefault
placementSnackbarPlacement'bottom-left' | 'bottom-center' | 'bottom-right''bottom-center'
Default position along the bottom edge.
durationnumber4000
Default lifetime in milliseconds. 0 disables automatic dismissal.
actionTextstringnone
Default action text and accessible name. Defaults to the dictionary.
labelstringnone
Accessible snackbar region name. Defaults to the dictionary.

CSS variables

TokenValue
--vectis-control-size-snackbar-min18rem
--vectis-control-size-snackbar-max36rem