Anatomy
A toast is a small card with a coloured top border matching its variant, an optional icon and title, a description, an optional actions row, a dismiss button, and an optional progress bar. Multiple toasts at the same position share a single portal container appended to the end of document.body.

| Item | Name | Description |
|---|---|---|
1 |
Top border | 4px coloured strip indicating the variant (error/warning/success/info), or the neutral appearance border for default. |
2 |
Icon | Optional, user-provided via the icon slot. No icon ships by default. |
3 |
Title | Optional bold heading via the title slot. |
4 |
Description | The default slot — the toast's main message. |
5 |
Actions | Optional buttons or links via the actions slot — undo, retry, view details. |
6 |
Dismiss button | Closes the toast. Hidden when is-dismissible="false". |
7 |
Progress bar | Optional countdown strip shown when is-progress-enabled="true" and duration is greater than 0. |
Basics
aegov-toast is most often used imperatively through a global helper installed at window.aegovToast. Calling .show(options) creates a toast, mounts it inside a per-position portal container at the end of document.body, and shows it — all in a single call, with no <aegov-toast> markup or ref required for the common case.
<aegov-button id="trigger-toast" variant="primary">Submit application</aegov-button>
<script>
document.getElementById('trigger-toast').addEventListener('click', () => {
window.aegovToast.show({
message: 'Application submitted successfully.',
variant: 'success',
position: 'top-right',
duration: 4000,
});
});
</script>
import { AegovButton } from '@aegov/designsystem-react';
export default function ToastBasics() {
const showToast = () => {
(window as any).aegovToast.show({
message: 'Application submitted successfully.',
variant: 'success',
position: 'top-right',
duration: 4000,
});
};
return <AegovButton onClick={showToast}>Submit application</AegovButton>;
}
<template>
<aegov-button @click="showToast">Submit application</aegov-button>
</template>
<script setup>
function showToast() {
window.aegovToast.show({
message: 'Application submitted successfully.',
variant: 'success',
position: 'top-right',
duration: 4000,
});
}
</script>
import { Component } from '@angular/core';
import { AegovButton } from '@aegov/designsystem-angular';
@Component({
selector: 'app-toast-basics',
imports: [AegovButton],
template: `<aegov-button (click)="showToast()">Submit application</aegov-button>`,
})
export class ToastBasicsComponent {
showToast() {
(window as any).aegovToast.show({
message: 'Application submitted successfully.',
variant: 'success',
position: 'top-right',
duration: 4000,
});
}
}
Variants
variant sets the semantic colour of the 4px top border. default (no border colour) suits neutral confirmations; success, info, warning, and error add a coloured top border in the corresponding palette. error and warning are announced through the assertive live region — see Accessibility below.
<div class="flex flex-wrap gap-3">
<aegov-button id="variant-default" appearance="outline">Default</aegov-button>
<aegov-button id="variant-success" variant="primary">Success</aegov-button>
<aegov-button id="variant-info" variant="secondary">Info</aegov-button>
<aegov-button id="variant-warning" appearance="outline">Warning</aegov-button>
<aegov-button id="variant-error" appearance="outline">Error</aegov-button>
</div>
<script>
const map = {
'variant-default': { variant: 'default', message: 'Your draft has been saved.' },
'variant-success': { variant: 'success', message: 'Application submitted successfully.' },
'variant-info': { variant: 'info', message: 'A new policy update is available.' },
'variant-warning': { variant: 'warning', message: 'Your session expires in 5 minutes.' },
'variant-error': { variant: 'error', message: 'Unable to save changes. Please try again.' },
};
Object.keys(map).forEach(id => {
document.getElementById(id).addEventListener('click', () => {
window.aegovToast.show({ ...map[id], position: 'top-right', duration: 4000 });
});
});
</script>
import { AegovButton } from '@aegov/designsystem-react';
const variants = [
{ key: 'default', label: 'Default', message: 'Your draft has been saved.' },
{ key: 'success', label: 'Success', message: 'Application submitted successfully.' },
{ key: 'info', label: 'Info', message: 'A new policy update is available.' },
{ key: 'warning', label: 'Warning', message: 'Your session expires in 5 minutes.' },
{ key: 'error', label: 'Error', message: 'Unable to save changes. Please try again.' },
] as const;
export default function ToastVariants() {
const show = (variant: string, message: string) => {
(window as any).aegovToast.show({ variant, message, position: 'top-right', duration: 4000 });
};
return (
<div className="flex flex-wrap gap-3">
{variants.map(v => (
<AegovButton key={v.key} onClick={() => show(v.key, v.message)}>{v.label}</AegovButton>
))}
</div>
);
}
<template>
<div class="flex flex-wrap gap-3">
<aegov-button v-for="v in variants" :key="v.key" @click="show(v.key, v.message)">{{ v.label }}</aegov-button>
</div>
</template>
<script setup>
const variants = [
{ key: 'default', label: 'Default', message: 'Your draft has been saved.' },
{ key: 'success', label: 'Success', message: 'Application submitted successfully.' },
{ key: 'info', label: 'Info', message: 'A new policy update is available.' },
{ key: 'warning', label: 'Warning', message: 'Your session expires in 5 minutes.' },
{ key: 'error', label: 'Error', message: 'Unable to save changes. Please try again.' },
];
function show(variant, message) {
window.aegovToast.show({ variant, message, position: 'top-right', duration: 4000 });
}
</script>
import { Component } from '@angular/core';
import { AegovButton } from '@aegov/designsystem-angular';
@Component({
selector: 'app-toast-variants',
imports: [AegovButton],
template: `
<div class="flex flex-wrap gap-3">
@for (v of variants; track v.key) {
<aegov-button (click)="show(v.key, v.message)">{{ v.label }}</aegov-button>
}
</div>
`,
})
export class ToastVariantsComponent {
variants = [
{ key: 'default', label: 'Default', message: 'Your draft has been saved.' },
{ key: 'success', label: 'Success', message: 'Application submitted successfully.' },
{ key: 'info', label: 'Info', message: 'A new policy update is available.' },
{ key: 'warning', label: 'Warning', message: 'Your session expires in 5 minutes.' },
{ key: 'error', label: 'Error', message: 'Unable to save changes. Please try again.' },
];
show(variant: string, message: string) {
(window as any).aegovToast.show({ variant, message, position: 'top-right', duration: 4000 });
}
}
Appearance
appearance controls the surface treatment. soft (default) is a white background with dark text, suitable for most cases. solid is a dark background with white text, useful when a toast needs to read as a system-level message regardless of the page background.
<aegov-button id="appearance-soft" appearance="outline">Soft appearance</aegov-button>
<aegov-button id="appearance-solid" variant="primary">Solid appearance</aegov-button>
<script>
document.getElementById('appearance-soft').addEventListener('click', () => {
window.aegovToast.show({ message: 'Application submitted.', variant: 'success', appearance: 'soft', position: 'top-right', duration: 4000 });
});
document.getElementById('appearance-solid').addEventListener('click', () => {
window.aegovToast.show({ message: 'Application submitted.', variant: 'success', appearance: 'solid', position: 'top-right', duration: 4000 });
});
</script>
import { AegovButton } from '@aegov/designsystem-react';
export default function ToastAppearance() {
const show = (appearance: 'soft' | 'solid') => {
(window as any).aegovToast.show({ message: 'Application submitted.', variant: 'success', appearance, position: 'top-right', duration: 4000 });
};
return (
<div className="flex flex-wrap gap-3">
<AegovButton appearance="outline" onClick={() => show('soft')}>Soft appearance</AegovButton>
<AegovButton onClick={() => show('solid')}>Solid appearance</AegovButton>
</div>
);
}
<template>
<div class="flex flex-wrap gap-3">
<aegov-button appearance="outline" @click="show('soft')">Soft appearance</aegov-button>
<aegov-button @click="show('solid')">Solid appearance</aegov-button>
</div>
</template>
<script setup>
function show(appearance) {
window.aegovToast.show({ message: 'Application submitted.', variant: 'success', appearance, position: 'top-right', duration: 4000 });
}
</script>
import { Component } from '@angular/core';
import { AegovButton } from '@aegov/designsystem-angular';
@Component({
selector: 'app-toast-appearance',
imports: [AegovButton],
template: `
<div class="flex flex-wrap gap-3">
<aegov-button appearance="outline" (click)="show('soft')">Soft appearance</aegov-button>
<aegov-button (click)="show('solid')">Solid appearance</aegov-button>
</div>
`,
})
export class ToastAppearanceComponent {
show(appearance: 'soft' | 'solid') {
(window as any).aegovToast.show({ message: 'Application submitted.', variant: 'success', appearance, position: 'top-right', duration: 4000 });
}
}
Position
position anchors the toast to a corner or edge of the viewport. Each position has its own portal container, so a single page can run multiple stacks at once — for example a confirmation top-right and a connectivity warning bottom-center.
| Value | Anchor |
|---|---|
top-right |
Default. Aligned to the inline-end of the viewport. |
top-left |
Aligned to the inline-start of the viewport. |
top-center |
Centred along the top edge. |
bottom-right |
Aligned to the inline-end at the bottom. |
bottom-left |
Aligned to the inline-start at the bottom. |
bottom-center |
Centred along the bottom edge. |
<div class="grid grid-cols-3 gap-3 max-w-md">
<aegov-button id="pos-tl" appearance="outline" size="sm">Top left</aegov-button>
<aegov-button id="pos-tc" appearance="outline" size="sm">Top center</aegov-button>
<aegov-button id="pos-tr" appearance="outline" size="sm">Top right</aegov-button>
<aegov-button id="pos-bl" appearance="outline" size="sm">Bottom left</aegov-button>
<aegov-button id="pos-bc" appearance="outline" size="sm">Bottom center</aegov-button>
<aegov-button id="pos-br" appearance="outline" size="sm">Bottom right</aegov-button>
</div>
<script>
const positions = {
'pos-tl': 'top-left', 'pos-tc': 'top-center', 'pos-tr': 'top-right',
'pos-bl': 'bottom-left', 'pos-bc': 'bottom-center', 'pos-br': 'bottom-right',
};
Object.keys(positions).forEach(id => {
document.getElementById(id).addEventListener('click', () => {
window.aegovToast.show({ message: 'Toast at ' + positions[id], variant: 'info', position: positions[id], duration: 4000 });
});
});
</script>
import { AegovButton } from '@aegov/designsystem-react';
const positions = [
{ key: 'top-left', label: 'Top left' },
{ key: 'top-center', label: 'Top center' },
{ key: 'top-right', label: 'Top right' },
{ key: 'bottom-left', label: 'Bottom left' },
{ key: 'bottom-center', label: 'Bottom center' },
{ key: 'bottom-right', label: 'Bottom right' },
] as const;
export default function ToastPosition() {
const show = (position: string) => {
(window as any).aegovToast.show({ message: `Toast at ${position}`, variant: 'info', position, duration: 4000 });
};
return (
<div className="grid grid-cols-3 gap-3 max-w-md">
{positions.map(p => (
<AegovButton key={p.key} appearance="outline" size="sm" onClick={() => show(p.key)}>{p.label}</AegovButton>
))}
</div>
);
}
<template>
<div class="grid grid-cols-3 gap-3 max-w-md">
<aegov-button v-for="p in positions" :key="p.key" appearance="outline" size="sm" @click="show(p.key)">{{ p.label }}</aegov-button>
</div>
</template>
<script setup>
const positions = [
{ key: 'top-left', label: 'Top left' },
{ key: 'top-center', label: 'Top center' },
{ key: 'top-right', label: 'Top right' },
{ key: 'bottom-left', label: 'Bottom left' },
{ key: 'bottom-center', label: 'Bottom center' },
{ key: 'bottom-right', label: 'Bottom right' },
];
function show(position) {
window.aegovToast.show({ message: `Toast at ${position}`, variant: 'info', position, duration: 4000 });
}
</script>
import { Component } from '@angular/core';
import { AegovButton } from '@aegov/designsystem-angular';
@Component({
selector: 'app-toast-position',
imports: [AegovButton],
template: `
<div class="grid grid-cols-3 gap-3 max-w-md">
@for (p of positions; track p.key) {
<aegov-button appearance="outline" size="sm" (click)="show(p.key)">{{ p.label }}</aegov-button>
}
</div>
`,
})
export class ToastPositionComponent {
positions = [
{ key: 'top-left', label: 'Top left' },
{ key: 'top-center', label: 'Top center' },
{ key: 'top-right', label: 'Top right' },
{ key: 'bottom-left', label: 'Bottom left' },
{ key: 'bottom-center', label: 'Bottom center' },
{ key: 'bottom-right', label: 'Bottom right' },
];
show(position: string) {
(window as any).aegovToast.show({ message: `Toast at ${position}`, variant: 'info', position, duration: 4000 });
}
}
Duration and auto-dismiss
duration is the auto-dismiss timeout in milliseconds. Hovering the toast — or moving keyboard focus into it — pauses the timer; leaving resumes it from the exact remaining time. Set duration: 0 to disable auto-dismiss entirely, so the user must click the close button.
<aegov-button id="dur-fast" appearance="outline">Quick (2s)</aegov-button>
<aegov-button id="dur-long" appearance="outline">Long (8s)</aegov-button>
<aegov-button id="dur-persist" appearance="outline">Persistent</aegov-button>
<script>
document.getElementById('dur-fast').addEventListener('click', () => {
window.aegovToast.show({ message: 'Quick confirmation.', variant: 'success', duration: 2000, position: 'top-right' });
});
document.getElementById('dur-long').addEventListener('click', () => {
window.aegovToast.show({ message: 'Document downloaded.', variant: 'success', duration: 8000, position: 'top-right' });
});
document.getElementById('dur-persist').addEventListener('click', () => {
window.aegovToast.show({ message: 'You are offline. Some features may be unavailable.', variant: 'warning', duration: 0, position: 'top-right' });
});
</script>
import { AegovButton } from '@aegov/designsystem-react';
export default function ToastDuration() {
return (
<div className="flex flex-wrap gap-3">
<AegovButton appearance="outline" onClick={() => (window as any).aegovToast.show({ message: 'Quick confirmation.', variant: 'success', duration: 2000, position: 'top-right' })}>Quick (2s)</AegovButton>
<AegovButton appearance="outline" onClick={() => (window as any).aegovToast.show({ message: 'Document downloaded.', variant: 'success', duration: 8000, position: 'top-right' })}>Long (8s)</AegovButton>
<AegovButton appearance="outline" onClick={() => (window as any).aegovToast.show({ message: 'You are offline. Some features may be unavailable.', variant: 'warning', duration: 0, position: 'top-right' })}>Persistent</AegovButton>
</div>
);
}
<template>
<div class="flex flex-wrap gap-3">
<aegov-button appearance="outline" @click="fast">Quick (2s)</aegov-button>
<aegov-button appearance="outline" @click="long">Long (8s)</aegov-button>
<aegov-button appearance="outline" @click="persist">Persistent</aegov-button>
</div>
</template>
<script setup>
function fast() {
window.aegovToast.show({ message: 'Quick confirmation.', variant: 'success', duration: 2000, position: 'top-right' });
}
function long() {
window.aegovToast.show({ message: 'Document downloaded.', variant: 'success', duration: 8000, position: 'top-right' });
}
function persist() {
window.aegovToast.show({ message: 'You are offline. Some features may be unavailable.', variant: 'warning', duration: 0, position: 'top-right' });
}
</script>
import { Component } from '@angular/core';
import { AegovButton } from '@aegov/designsystem-angular';
@Component({
selector: 'app-toast-duration',
imports: [AegovButton],
template: `
<div class="flex flex-wrap gap-3">
<aegov-button appearance="outline" (click)="fast()">Quick (2s)</aegov-button>
<aegov-button appearance="outline" (click)="long()">Long (8s)</aegov-button>
<aegov-button appearance="outline" (click)="persist()">Persistent</aegov-button>
</div>
`,
})
export class ToastDurationComponent {
fast() {
(window as any).aegovToast.show({ message: 'Quick confirmation.', variant: 'success', duration: 2000, position: 'top-right' });
}
long() {
(window as any).aegovToast.show({ message: 'Document downloaded.', variant: 'success', duration: 8000, position: 'top-right' });
}
persist() {
(window as any).aegovToast.show({ message: 'You are offline. Some features may be unavailable.', variant: 'warning', duration: 0, position: 'top-right' });
}
}
Progress bar
Set isProgressEnabled: true (is-progress-enabled attribute) to render a thin countdown bar across the bottom of the toast. It pauses whenever the auto-dismiss timer pauses — on hover or keyboard focus — and has no effect when duration is 0.
<aegov-button id="show-progress" variant="primary">Submit with progress bar</aegov-button>
<script>
document.getElementById('show-progress').addEventListener('click', () => {
window.aegovToast.show({
message: 'Application submitted to the Ministry of Interior.',
variant: 'success',
duration: 6000,
isProgressEnabled: true,
position: 'top-right',
});
});
</script>
import { AegovButton } from '@aegov/designsystem-react';
export default function ToastProgress() {
const show = () => {
(window as any).aegovToast.show({
message: 'Application submitted to the Ministry of Interior.',
variant: 'success',
duration: 6000,
isProgressEnabled: true,
position: 'top-right',
});
};
return <AegovButton onClick={show}>Submit with progress bar</AegovButton>;
}
<template>
<aegov-button @click="show">Submit with progress bar</aegov-button>
</template>
<script setup>
function show() {
window.aegovToast.show({
message: 'Application submitted to the Ministry of Interior.',
variant: 'success',
duration: 6000,
isProgressEnabled: true,
position: 'top-right',
});
}
</script>
import { Component } from '@angular/core';
import { AegovButton } from '@aegov/designsystem-angular';
@Component({
selector: 'app-toast-progress',
imports: [AegovButton],
template: `<aegov-button (click)="show()">Submit with progress bar</aegov-button>`,
})
export class ToastProgressComponent {
show() {
(window as any).aegovToast.show({
message: 'Application submitted to the Ministry of Interior.',
variant: 'success',
duration: 6000,
isProgressEnabled: true,
position: 'top-right',
});
}
}
Stack vs rack mode
When several toasts land at the same position, mode controls how they lay out. stack (default) shows every toast with a small gap between them. rack collapses them into a single deck — the newest is fully visible, older toasts peek behind it scaled and faded, and a count badge shows the total. Hovering or focusing the deck expands it back into a stack.
<aegov-button id="mode-stack" appearance="outline">Fire 3 stacked toasts</aegov-button>
<aegov-button id="mode-rack" variant="primary">Fire 4 racked toasts</aegov-button>
<script>
document.getElementById('mode-stack').addEventListener('click', () => {
['Application received', 'Documents validated', 'Payment confirmed'].forEach((msg, i) => {
setTimeout(() => window.aegovToast.show({ message: msg, variant: 'success', mode: 'stack', position: 'top-right', duration: 5000 }), i * 250);
});
});
document.getElementById('mode-rack').addEventListener('click', () => {
['New application received', 'Document uploaded', 'Officer assigned', 'Status updated'].forEach((msg, i) => {
setTimeout(() => window.aegovToast.show({ message: msg, variant: 'info', mode: 'rack', position: 'bottom-right', duration: 0 }), i * 200);
});
});
</script>
import { AegovButton } from '@aegov/designsystem-react';
export default function ToastStackRack() {
const fireStack = () => {
['Application received', 'Documents validated', 'Payment confirmed'].forEach((message, i) => {
setTimeout(() => (window as any).aegovToast.show({ message, variant: 'success', mode: 'stack', position: 'top-right', duration: 5000 }), i * 250);
});
};
const fireRack = () => {
['New application received', 'Document uploaded', 'Officer assigned', 'Status updated'].forEach((message, i) => {
setTimeout(() => (window as any).aegovToast.show({ message, variant: 'info', mode: 'rack', position: 'bottom-right', duration: 0 }), i * 200);
});
};
return (
<div className="flex flex-wrap gap-3">
<AegovButton appearance="outline" onClick={fireStack}>Fire 3 stacked toasts</AegovButton>
<AegovButton onClick={fireRack}>Fire 4 racked toasts</AegovButton>
</div>
);
}
<template>
<div class="flex flex-wrap gap-3">
<aegov-button appearance="outline" @click="fireStack">Fire 3 stacked toasts</aegov-button>
<aegov-button @click="fireRack">Fire 4 racked toasts</aegov-button>
</div>
</template>
<script setup>
function fireStack() {
['Application received', 'Documents validated', 'Payment confirmed'].forEach((message, i) => {
setTimeout(() => window.aegovToast.show({ message, variant: 'success', mode: 'stack', position: 'top-right', duration: 5000 }), i * 250);
});
}
function fireRack() {
['New application received', 'Document uploaded', 'Officer assigned', 'Status updated'].forEach((message, i) => {
setTimeout(() => window.aegovToast.show({ message, variant: 'info', mode: 'rack', position: 'bottom-right', duration: 0 }), i * 200);
});
}
</script>
import { Component } from '@angular/core';
import { AegovButton } from '@aegov/designsystem-angular';
@Component({
selector: 'app-toast-stack-rack',
imports: [AegovButton],
template: `
<div class="flex flex-wrap gap-3">
<aegov-button appearance="outline" (click)="fireStack()">Fire 3 stacked toasts</aegov-button>
<aegov-button (click)="fireRack()">Fire 4 racked toasts</aegov-button>
</div>
`,
})
export class ToastStackRackComponent {
fireStack() {
['Application received', 'Documents validated', 'Payment confirmed'].forEach((message, i) => {
setTimeout(() => (window as any).aegovToast.show({ message, variant: 'success', mode: 'stack', position: 'top-right', duration: 5000 }), i * 250);
});
}
fireRack() {
['New application received', 'Document uploaded', 'Officer assigned', 'Status updated'].forEach((message, i) => {
setTimeout(() => (window as any).aegovToast.show({ message, variant: 'info', mode: 'rack', position: 'bottom-right', duration: 0 }), i * 200);
});
}
}
Title, icon, and actions slots
A toast can carry more than description text: title for a bold heading, icon for a custom leading icon (none ships by default), and actions for buttons or links such as an inline undo. These need real slotted markup, added before the toast is connected — slot presence and the announced text are both captured when the element loads. A toast declared in plain HTML stays hidden until show() runs, so pre-declared markup works. In a framework app, though, build the <aegov-toast> element in your click handler, not as pre-mounted JSX/template markup: show() moves the element out of the framework's tree and close() removes it from the DOM — construct it on demand instead, exactly as window.aegovToast.show() does internally.
<aegov-button id="show-undo">Move to trash</aegov-button>
<script>
document.getElementById('show-undo').addEventListener('click', () => {
const toast = document.createElement('aegov-toast');
toast.variant = 'default';
toast.duration = 6000;
toast.innerHTML = `
<svg slot="icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<polyline points="3 6 5 6 21 6"/>
<path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"/>
</svg>
<span slot="title">Application moved to trash</span>
You can restore it within 30 days.
<aegov-button slot="actions" appearance="link" size="sm">Undo</aegov-button>
`;
document.body.appendChild(toast);
toast.show();
});
</script>
import { AegovButton } from '@aegov/designsystem-react';
export default function ToastActions() {
const handleClick = () => {
const toast = document.createElement('aegov-toast');
toast.variant = 'default';
toast.duration = 6000;
toast.innerHTML = `
<svg slot="icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<polyline points="3 6 5 6 21 6"/>
<path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"/>
</svg>
<span slot="title">Application moved to trash</span>
You can restore it within 30 days.
<aegov-button slot="actions" appearance="link" size="sm">Undo</aegov-button>
`;
document.body.appendChild(toast);
toast.show();
};
return <AegovButton onClick={handleClick}>Move to trash</AegovButton>;
}
<template>
<aegov-button @click="handleClick">Move to trash</aegov-button>
</template>
<script setup>
function handleClick() {
const toast = document.createElement('aegov-toast');
toast.variant = 'default';
toast.duration = 6000;
toast.innerHTML = `
<svg slot="icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<polyline points="3 6 5 6 21 6"/>
<path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"/>
</svg>
<span slot="title">Application moved to trash</span>
You can restore it within 30 days.
<aegov-button slot="actions" appearance="link" size="sm">Undo</aegov-button>
`;
document.body.appendChild(toast);
toast.show();
}
</script>
import { Component } from '@angular/core';
import { AegovButton } from '@aegov/designsystem-angular';
@Component({
selector: 'app-toast-actions',
imports: [AegovButton],
template: `<aegov-button (click)="showToast()">Move to trash</aegov-button>`,
})
export class ToastActionsComponent {
showToast() {
const toast = document.createElement('aegov-toast');
toast.variant = 'default';
toast.duration = 6000;
toast.innerHTML = `
<svg slot="icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<polyline points="3 6 5 6 21 6"/>
<path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"/>
</svg>
<span slot="title">Application moved to trash</span>
You can restore it within 30 days.
<aegov-button slot="actions" appearance="link" size="sm">Undo</aegov-button>
`;
document.body.appendChild(toast);
toast.show();
}
}
RTL support
Toast containers use logical CSS properties, so a -right position resolves to the inline-end edge and a -left position to the inline-start edge under RTL. The container and each toast are appended straight to document.body, though — not left inside wherever the trigger button lives — so they only inherit dir from <html>/<body>, never from a wrapper placed around the trigger. For a whole Arabic page, set dir="rtl" on <html> and every toast mirrors automatically. For a single RTL toast on an otherwise-LTR page, set dir="rtl" directly on a declared <aegov-toast> element, as shown below — the value travels with the element when it moves into its portal container.
<aegov-toast id="rtl-toast" dir="rtl" variant="success" duration="0">
تم إرسال الطلب بنجاح. ستصلك رسالة نصية خلال 3 أيام عمل.
</aegov-toast>
<aegov-button id="show-rtl-toast" variant="primary">إرسال الطلب</aegov-button>
<script>
document.getElementById('show-rtl-toast').addEventListener('click', () => {
document.getElementById('rtl-toast').show();
});
</script>
import { useRef } from 'react';
import { AegovButton, AegovToast } from '@aegov/designsystem-react';
export default function RtlToast() {
const toastRef = useRef<HTMLAegovToastElement>(null);
return (
<>
<AegovToast ref={toastRef} dir="rtl" variant="success" duration={0}>
تم إرسال الطلب بنجاح. ستصلك رسالة نصية خلال 3 أيام عمل.
</AegovToast>
<AegovButton onClick={() => toastRef.current?.show()}>إرسال الطلب</AegovButton>
</>
);
}
<template>
<aegov-toast ref="toast" dir="rtl" variant="success" duration="0">
تم إرسال الطلب بنجاح. ستصلك رسالة نصية خلال 3 أيام عمل.
</aegov-toast>
<aegov-button @click="toast?.show()">إرسال الطلب</aegov-button>
</template>
<script setup>
import { ref } from 'vue';
const toast = ref(null);
</script>
import { Component, ViewChild, ElementRef } from '@angular/core';
import { AegovButton, AegovToast } from '@aegov/designsystem-angular';
@Component({
selector: 'app-rtl-toast',
imports: [AegovButton, AegovToast],
template: `
<aegov-toast #toast dir="rtl" variant="success" duration="0">
تم إرسال الطلب بنجاح. ستصلك رسالة نصية خلال 3 أيام عمل.
</aegov-toast>
<aegov-button (click)="toast.show()">إرسال الطلب</aegov-button>
`,
})
export class RtlToastComponent {
@ViewChild('toast') toast!: ElementRef;
}
Usage
Here is the recommended usage of a toast on any website or application. These are recommended usage guides, however the developer must use the best practices of web and application development to accurately use this component.
Use the imperative window.aegovToast.show() helper for the common case
It creates, mounts, and shows a toast in one call, without needing a ref or manual element management.
Set dir="rtl" on <html> for a fully Arabic page
Every toast then inherits it automatically, since the portal container lives inside <body>. Only reach for setting dir on an individual declared <aegov-toast> element when a single toast must render RTL on an otherwise-LTR page.
Set duration to at least 6000ms for a destructive undo affordance
Give the user enough time to notice an action-bearing toast such as "Moved to trash… Undo" before it disappears.
Reserve error/warning variants for genuinely urgent messages
They route through the assertive live region and interrupt the screen reader. Overusing them for routine confirmations desensitises users to real warnings.
Don't use a toast as the only place critical information appears
It can auto-dismiss, be dismissed by the user, or be missed entirely. For anything the user must acknowledge, use aegov-modal instead.
Don't rely on a dir="rtl" wrapper around the trigger button to RTL a toast
The toast and its container are appended straight to document.body, outside that wrapper, so it silently renders LTR. See the RTL support section for the pattern that actually works.
API reference
The following are the properties and references of a toast
aegov-toast properties
| Attribute | Description | Type | Default |
|---|---|---|---|
| Semantic colour. Sets the 4px coloured top border. |
|
|
| Surface treatment. |
|
|
| Viewport corner or edge to anchor to. Each position gets its own portal container appended to |
|
|
| Auto-dismiss timeout in milliseconds. |
|
|
| Whether to render the close button. |
|
|
|
|
|
|
| When |
|
|
Slots
| Slot | Description |
|---|---|
(default) | The toast description text. Accepts inline HTML when passed through the |
| Bold heading rendered above the description. |
| User-provided icon rendered at the inline start of the content (left in LTR, right in RTL); |
| Buttons or links rendered below the description — undo, retry, view details. |
Events
| Event | Detail | Description |
|---|---|---|
|
| Fired after the toast becomes visible (once the entry animation has been queued). |
|
| Fired at the end of the 300ms exit animation, immediately before the toast element is removed from the DOM. Fires for every close path — timer, dismiss button, or |
|
| Fired when the user clicks the dismiss button, before the exit animation — and so before |
Methods
| Method | Returns | Description |
|---|---|---|
|
| Move the toast into its per-position portal container, run the entry animation, announce the message, and start the auto-dismiss timer. Does nothing while the toast is already visible. |
|
| Stop the timer, run the exit animation, fire |
Pass-through attributes
| Attribute | Notes | Forwards to |
|---|---|---|
| Not forwarded — the component manages its own ARIA semantics (the dismiss button label, the live-region announcement). Apply directly to | host |
| Not forwarded. Apply directly to | host |
| Apply directly to | n/a |
| A native global attribute, not a component Prop. Set it directly on | host & container |
| Applied to the host element. | host |
Notes
The following notes are applicable of this component.
Built-in accessibility
- Two persistent, reused, visually-hidden live regions exist at the document level: a polite region (
role="status",aria-live="polite",aria-atomic="true") fordefault,info, andsuccessvariants, and an assertive region (role="alert",aria-live="assertive",aria-atomic="true") forerrorandwarningvariants.show()selects the correct region automatically based onvariantand announces the toast's text content as captured when the element loaded — so set the content before adding the toast to the page; text changed afterwards is shown but not announced. - The dismiss button carries a bilingual, variant-aware
aria-label— e.g."Close success notification"in English,"إغلاق إشعار نجاح"in Arabic — with no developer translation needed. - Both mouse hover and keyboard focus pause the auto-dismiss timer and progress bar; leaving either resumes it from the exact remaining time (SC 2.2.1) — confirmed live: a toast held past its
durationwhile hovered remained on screen, then closed shortly after the pointer moved away. - In
rackmode, the deck expands on hover or keyboard focus moving into any toast in the rack, so keyboard users can reach every stacked toast, and collapses only once both leave. - Multiple toasts at the same position are never removed from the DOM while stacked. In
rackmode, the newest three stay readable (older ones peek behind, scaled and faded); toasts from the fourth onward are fully hidden and getaria-hidden="true"until the rack expands or newer toasts close. Each toast's live-region announcement still fires when it is shown. - A 300ms exit animation runs before
aegovToastClosefires and the element is removed from the DOM.
Developer responsibilities
- Keep toast text short and self-contained. Don't use a toast as the only place critical information appears — it can be missed or dismissed.
- For confirmations the user must acknowledge, use
aegov-modalinstead. - Give any button placed in
slot="actions"an actionable, descriptive label — "Undo", "View status", "Retry" — not a bare icon. - For a destructive undo affordance, set
durationto at least 6000ms so the user has time to react. - Set
dir="rtl"directly on a declared<aegov-toast>element for a single RTL toast — see RTL support above; it will not inheritdirfrom a wrapper around the trigger, since it and its container move todocument.body.
Keyboard support
| Key | Action |
|---|---|
Tab |
Move focus into the toast — its action button(s), then the dismiss button. |
Shift + Tab |
Move focus to the previous focusable element. |
Enter, Space |
Activate the focused button (an action button or the dismiss button). |