Skip to content
Focsd homeFocsd homeFocsd
Forms

Toast

Brief, non-blocking notifications. Place one toaster per page and call `show()`.

  • Tag: focsd-toaster
  • Pattern: Status / log region
  • Category: Feedback

Example

Save draft Show sticky toast
HTML
<focsd-button id="toast-demo">Save draft</focsd-button>
<focsd-button id="toast-demo-sticky">Show sticky toast</focsd-button>
<focsd-toaster id="toaster-demo"></focsd-toaster>
<script type="module">
const toaster = document.getElementById('toaster-demo');
document.getElementById('toast-demo').addEventListener('click', () => {
toaster.show({ message: 'Draft saved', tone: 'positive', action: { label: 'Undo', onClick: () => toaster.show({ message: 'Draft restored' }) } });
});
document.getElementById('toast-demo-sticky').addEventListener('click', () => {
toaster.show({ message: 'Sync paused while offline', tone: 'caution', duration: 0 });
});
</script>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/components/focsd-toaster.js';
</script>
<focsd-toaster></focsd-toaster>

API

Attributes

AttributePropertyTypeDefault
placementplacement'bottom-end' | 'bottom-start' | 'top-end' | 'top-start'bottom-end

JavaScript properties

PropertyTypeDescription
show(options){ message, tone?, action?: { label, onClick }, duration? = 6000 }Adds a toast and returns its id. duration: 0 keeps it until dismissed.
dismiss(id)numberRemoves a toast.

Methods

MethodDescription
show({ message, tone = 'neutral', action, duration = DEFAULT_DURATION }, options)Show a toast. Returns its id. duration: 0 keeps it until dismissed.
dismiss(id)Dismiss the toast with this id.

CSS parts

Style the inside of the component with ::part(), for example focsd-toaster::part(action).

PartDescription
actionThe action element.
dismissThe dismiss element.
listThe list element.
messageThe message element.
regionThe region element.
toastThe toast element.

Accessibility

  • The toaster is a polite role="status" live region that exists before toasts arrive, so every message is announced.
  • Toasts never take focus. Timers pause while hovered or focused (WCAG 2.2.1); each toast has a "Dismiss notification" button.
  • Do not put the only path to an action in a toast.