Skip to content

useToast ​

Queue-backed notifications. One shared queue serves the whole app, and the module mounts the Toast host that draws it — you never place a container.

Live Demo ​

In the queue: 0

API ​

typescript
const {
  toasts,
  showToast,
  closeToast,
  clearToasts,
  pauseToast,
  resumeToast,
  triggerAction,
  setToastDefaults,
} = useToast();
MemberSignatureDescription
toastsRef<ToastItem[]>The live queue, oldest first
showToast(options: ToastOptions) => stringQueues a toast, returns its id
closeToast(id: string) => voidRemoves one toast
clearToasts() => voidEmpties the queue
pauseToast(id: string) => voidHolds a countdown where it stands
resumeToast(id: string) => voidRuns the remaining time
triggerAction(toast, action) => Promise<void>Runs an action and applies its close behavior
setToastDefaults(overrides: Partial<ToastDefaults>) => voidChanges defaults for toasts shown afterwards

ToastOptions ​

OptionTypeDefaultDescription
messagestringrequiredBody text
titlestring—Bold line above the message
variant"info" | "success" | "alert" | "danger""info"Color family and urgency
positionToastPosition"bottom-end"Which stack it joins
targetToastTargetviewportScope the toast inside an element
timeoutnumber5000Milliseconds before auto-dismiss; 0 sticks
closablebooleantrueRenders the close button
showTimeoutbooleanfalseDraws a depleting bar for the remaining time
actionsToastAction[][]Buttons rendered on the trailing side

ToastPosition is one of top-start, top-center, top-end, bottom-start, bottom-center, bottom-end.

ToastTarget is string | HTMLElement | Ref<HTMLElement | null | undefined>, so an unresolved template ref is a valid target.

ToastAction ​

FieldTypeDescription
labelstringButton text
variant"primary" | "secondary" | "subdued"Button variant, defaults to "secondary"
iconstringIcon name passed to the button
keepOpenbooleanLeave the toast up after the handler resolves
onClick({ close, toast }) => void | Promise<void>Handler; close() dismisses early

Basic Usage ​

vue
<script setup>
const { showToast } = useToast();

function save() {
  showToast({ message: "Changes saved", variant: "success" });
}
</script>

Actions ​

A handler runs first, then the toast closes itself. An async handler keeps the toast on screen until it resolves, so a slow undo stays visible while it works.

vue
<script setup>
const { showToast } = useToast();

function deleteFile(file) {
  showToast({
    message: "File deleted",
    timeout: 0,
    actions: [
      // closes once restore() resolves
      { label: "Undo", onClick: () => restore(file) },

      // stays open
      { label: "Details", keepOpen: true, onClick: ({ close }) => openModal() },
    ],
  });
}
</script>

Queue toasts from event handlers or onMounted — never from the setup body, which also runs on the server.

Scoping to an element ​

vue
<script setup>
const panel = ref(null);
const { showToast } = useToast();

function notifyInPanel() {
  showToast({
    message: "Saved to this panel",
    target: panel,
    position: "top-end",
  });
}
</script>

<template>
  <section ref="panel">
    <orio-button @click="notifyInPanel">Notify</orio-button>
  </section>
</template>

A static target is switched to position: relative so its toasts anchor to it. Selectors ("#sidebar") are resolved to their element, so they behave exactly like passing that element; a selector that matches nothing falls back to the viewport corner.

Defaults ​

typescript
setToastDefaults({
  variant: "info",
  position: "bottom-end",
  timeout: 5000,
  closable: true,
  showTimeout: false,
  limit: 5,
});

The bar freezes whenever its stack is hovered or focused, since the countdown it draws is frozen too. Sticky toasts (timeout: 0) never draw one.

limit counts per stack — one position on one target — so a busy corner drops its oldest toast while other corners are untouched.