Components

Toast

Queued status and alert notifications with stacking, actions, updates, promise state, and swipe dismissal.

Toast renders an accessible notification viewport for messages created through useToast(). Visual type and announcement urgency are independent, duplicate messages are allowed, stable ids update in place, and timers pause while users inspect the queue.

Anatomy

  • #toast: Replaces all content inside the library-owned accessible toast root.
  • #title: Replaces title content.
  • #description: Replaces description content.
  • #close: Replaces close-button content.

The viewport and each toast root remain library-owned so live-region, queue, swipe, limit, and lifecycle behavior cannot be removed accidentally.

Usage

Open: 0

Examples

Visual type and urgency

Use type for styling and priority for announcement urgency. error and alert default to high priority; all other types default to low priority.

toast.add({
  title: "Storage nearly full",
  description: "Less than 10% remains.",
  type: "warning",
  priority: "high",
});

Duplicates and stable updates

Calls without id create independent notifications, even when content is identical. Reusing an id updates that toast, increments updateKey, and restarts its timer.

toast.add({ title: "Comment received" });
toast.add({ title: "Comment received" }); // Separate toast

toast.add({ id: "sync", title: "Syncing", duration: 0 });
toast.update({ id: "sync", title: "Synced", type: "success", duration: 5000 });

Action button

Actions close after successful completion by default. Set closeOnSelect: false to keep the toast open. Rejected actions emit action-error and remain visible.

toast.add({
  title: "Connection lost",
  duration: 0,
  action: {
    label: "Retry",
    altText: "Retry connection",
    onSelect: reconnect,
  },
});

Promise updates

toast.promise() preserves one id while the source promise moves from loading to success or error.

await toast.promise(api.publish(), {
  loading: { title: "Publishing", duration: 0 },
  success: { title: "Published", type: "success" },
  error: { title: "Failed", type: "error" },
});

Custom content

#toast owns all inner markup. Root role, live-region attrs, swipe handlers, type/state attrs, and queue metadata remain intact. Notification metadata and the guarded default action lifecycle are exposed directly to custom content.

<Toast>
  <template #toast="{ toast, type, priority, action, performAction, close }">
    <article :data-type="type" :data-priority="priority">
      <strong>{{ toast.title }}</strong>
      <p>{{ toast.description }}</p>
      <button v-if="action" @click="performAction($event)">{{ action.label }}</button>
      <button @click="close()">Dismiss</button>
    </article>
  </template>
</Toast>

Scoped manager for SSR

Default manager is a convenient client-side singleton. Create and provide a scoped manager for SSR or independent notification regions.

<script setup lang="ts">
import { createToastManager, provideToastManager, Toast } from "akaza-ui";

const manager = provideToastManager(createToastManager({ duration: 6000 }));
</script>

<template>
  <RouterView />
  <Toast :manager="manager" />
</template>

API Reference

Toast Props

PropTypeDefaultDescription
positionToastPosition"bottom-right"Fixed viewport position.
limitnumber3Maximum interactive toasts; older items remain mounted but inert.
stackbooleantrueCollapses queue until viewport is hovered or focused.
gapnumber12Expanded distance between adjacent toasts in pixels.
peeknumber12Visible edge between collapsed toasts in pixels.
scaleStepnumber0.1Scale reduction for each toast behind the frontmost toast.
hotkeystring[]["F8"]Key combination that focuses viewport.
hotkeyLabelstring"Notifications"Accessible viewport label.
closeLabelstring"Dismiss notification"Accessible close-button label.
swipeDirection"up" | "right" | "down" | "left"inferred from positionDismiss direction.
swipeThresholdnumber50Required swipe distance in pixels.
pauseOnHoverbooleantruePauses timers while hovered.
pauseOnFocusbooleantruePauses timers while focus is inside viewport.
pauseOnWindowBlurbooleantruePauses timers while window/document is inactive.
teleportstring | false"body"Teleport target or inline rendering.
managerToastManagerinjected/default managerExplicit manager for scoped queues.
uiToastUiClasses for generated parts.

Emits

EventPayloadDescription
action-error(error, toast)Action rejected or threw; toast remains open.
swipe-start(toast, event)Swipe interaction started.
swipe-move(toast, event)Pointer moved during swipe.
swipe-cancel(toast, event)Swipe ended below threshold or was canceled.
swipe-end(toast, event)Swipe crossed threshold and closed toast.

useToast

MethodSignatureDescription
toastsComputedRef<ToastItem[]>Current open/closing queue.
add(options) => stringAdds a toast or updates same id.
update(options) => voidUpdates an existing toast and restarts timer.
close(id, reason?) => voidStarts close lifecycle and exit animation.
remove(id) => voidRemoves immediately.
clear(reason?) => voidCloses all toasts.
pause() => voidPauses all active timers with remaining duration.
resume() => voidResumes paused timers.
promise(promise, options) => Promise<T>Adds loading toast and updates on settle.

ToastAddOptions

KeyTypeDescription
idstringStable id. Same id updates existing toast.
titlestringToast title.
descriptionstringToast body.
typeToastTypeVisual variant exposed as data-akaza-type.
priority"low" | "high"Polite or assertive announcement.
durationnumberAuto-dismiss milliseconds; 0 is persistent.
actionToastActionOptional action with label, alt text, callback, and close behavior.
dataunknownCustom data available to slots.
onClose(reason) => voidCalled when close lifecycle begins.
onRemove() => voidCalled after item leaves manager.

Slots

SlotPropsDescription
toasttoast, type, priority, action, attrs, close, performActionComplete inner content override with direct metadata and built-in action lifecycle.
titletoastTitle content.
descriptiontoastDescription content.
closetoastClose-button content.

UI Options

KeyDescription
viewportFixed toast viewport.
toastAccessible toast root.
titleTitle element.
descriptionDescription element.
closeClose button.
actionAction button.

Styling Hooks

UI keyCSS classData attrs / CSS vars
viewportakaza-toast-viewportdata-akaza-side, data-akaza-align, data-akaza-expanded, data-akaza-stacked
toastakaza-toastdata-akaza-state, data-akaza-type, data-akaza-priority, data-akaza-expanded, data-akaza-behind, data-akaza-limited, data-akaza-index, data-akaza-swipe, data-akaza-swipe-direction, --akaza-toast-index, --akaza-toast-count, --akaza-toast-height, --akaza-toast-frontmost-height, --akaza-toast-offset-y, --akaza-toast-stack-y, --akaza-toast-scale, --akaza-toast-gap, --akaza-toast-peek, --akaza-toast-swipe-move-x, --akaza-toast-swipe-move-y, --akaza-toast-duration, --akaza-toast-height-duration, --akaza-toast-content-duration
titleakaza-toast-title
descriptionakaza-toast-description
closeakaza-toast-close
actionakaza-toast-action

Toast geometry follows its viewport edge. Bottom positions enter from below and expand upward; top positions enter from above and expand downward. A new toast slides in while existing toasts move and scale behind it in the same transition. Collapsed toasts expose only a scaled edge while content behind the frontmost toast fades out. The stack uses a 500ms eased transform, with separate 150ms height and 250ms content transitions. Override the duration variables as needed. Active swipe tracking remains immediate, and reduced-motion preference shortens all transitions automatically.

Keyboard

KeyBehavior
F8Focuses and expands viewport by default.
TabMoves through toast actions and close buttons.
EscapeCloses latest toast while focus is inside viewport.