Feedback
Alert
Free15.0 KB gzippedAn inline, in-page message: info, success, warning, danger, or neutral. Not a toast or a banner; it sits in the flow of the content it relates to.
Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Tab · Full report
Import
import { Alert } from "@vjdesigns/vjdesigns-ui";
Importing only Alert adds about 15.0 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.
Examples
Tones
Each tone has its own icon and a visually hidden label ("Warning:"), so meaning never depends on color.
Scheduled maintenance
Payment received
Warning: Storage almost full
Error: Couldn't save changes
import { Alert, Stack } from "@vjdesigns/vjdesigns-ui";
export function Tones() {
return (
<Stack gap={3} style={{ width: "100%" }}>
<Alert tone="info" title="Scheduled maintenance">
The dashboard will be read-only on Sunday from 2–3 AM UTC.
</Alert>
<Alert tone="success" title="Payment received">
Thanks! Your receipt is on its way.
</Alert>
<Alert tone="warning" title="Storage almost full">
You've used 92% of your storage.
</Alert>
<Alert tone="danger" title="Couldn't save changes">
Check your connection and try again.
</Alert>
</Stack>
);
}
Variants
Soft (default)
Solid
Outline
import { Alert, Stack } from "@vjdesigns/vjdesigns-ui";
export function Variants() {
return (
<Stack gap={3} style={{ width: "100%" }}>
<Alert variant="soft" tone="info" title="Soft (default)" />
<Alert variant="solid" tone="info" title="Solid" />
<Alert variant="outline" tone="info" title="Outline" />
</Stack>
);
}
Dismissible with actions
dismissible adds a close button; focus moves somewhere sensible when it closes. actions adds buttons.
Warning: Your trial ends in 3 days
import { useState } from "react";
import { Alert, Button } from "@vjdesigns/vjdesigns-ui";
export function DismissibleWithActions() {
const [open, setOpen] = useState(true);
if (!open) {
return (
<Button variant="outline" tone="neutral" onClick={() => setOpen(true)}>
Show alert again
</Button>
);
}
return (
<div style={{ width: "100%" }}>
<Alert
tone="warning"
title="Your trial ends in 3 days"
dismissible
onOpenChange={setOpen}
actions={
<Button size="sm" tone="neutral">
Upgrade now
</Button>
}
>
Upgrade to keep your projects and team members.
</Alert>
</div>
);
}
Accessibility
An alert's tone is also spoken (toneLabel, "Warning:"), so it doesn't depend on color or the icon. Use live only for alerts that appear in response to something, so they're announced; when a dismissed alert disappears, focus moves to returnFocusRef rather than getting lost.
import { useState } from "react";
import { Alert, Button, Stack } from "@vjdesigns/vjdesigns-ui";
export function Accessibility() {
const [shown, setShown] = useState(false);
return (
<Stack gap={3} style={{ width: "100%", maxWidth: "32rem" }}>
<Button variant="outline" tone="neutral" onClick={() => setShown(true)}>
Check storage
</Button>
{shown && (
<Alert tone="warning" title="Storage almost full" live="polite" dismissible onDismiss={() => setShown(false)}>
You've used 92% of your 10 GB. Delete old files or upgrade your plan.
</Alert>
)}
</Stack>
);
}
Translated
The spoken tone ("Avertissement :") and the dismiss button's name come from the locale (French here).
Avertissement : Paiement en attente
import { Alert, LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import fr from "@vjdesigns/vjdesigns-ui/locales/fr";
export function Translated() {
return (
<LocaleProvider locale="fr" messages={fr}>
<Alert tone="warning" title="Paiement en attente" dismissible style={{ width: "100%", maxWidth: "32rem" }}>
Votre carte expire ce mois-ci. Mettez-la à jour pour éviter une interruption.
</Alert>
</LocaleProvider>
);
}
Right to left
The first example again, inside a right-to-left LocaleProvider (Arabic). Layout, spacing and arrow icons mirror, and the components' built-in text is translated. The example's own text stays in English.
Tones
Scheduled maintenance
Payment received
تحذير: Storage almost full
خطأ: Couldn't save changes
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";
// Tones is the "Tones" example above.
<LocaleProvider locale="ar" messages={ar}>
<Tones />
</LocaleProvider>
Usage notes
Accessibility:
- Tone is never color alone: each tone has a distinct icon shape, and
danger/warningget a visually hidden "Error: "/"Warning: " prefix (seetoneLabel). livepicks the role: none (default),status(polite), oralert(assertive). Live roles only announce content inserted after page load.- The dismiss button is a native
<button>named "Dismiss" (at least 32x32). After dismissal, focus moves toreturnFocusRefwhen given. - With
as="section"oras="aside", the landmark is labelled by the title.
API reference
Alert
| Prop | Type | Default |
|---|---|---|
toneSemantic color and default icon. | "neutral""success""warning""danger""info" | "info" |
variantSurface style. | "soft""solid""outline" | "soft" |
titleBold display-font title. Optional; a description alone is fine for short messages. | ReactNode | — |
headingLevelRenders the title as a real heading ( | 123456 | — |
childrenDescription: the message body. May include links and lists. | ReactNode | — |
iconIcon in the tinted circle. Defaults to a distinct shape per tone (info, success check, warning triangle, error). Pass | ReactNode | false | — |
toneLabelVisually hidden prefix read before the title (or the description, when there is no title), e.g. "Error: ". | string | boolean | on for `danger` ("Error: ") and `warning` ("Warning: "), off otherwise |
actionsAction row under the description, usually | ReactNode | — |
dismissibleShows a "Dismiss" icon button at the end. | boolean | false |
dismissLabelAccessible name of the dismiss button. Localize it here. | string | "Dismiss" |
onDismissCalled when the dismiss button is pressed, after the alert hides. | () => void | — |
returnFocusRefElement to focus after dismissal, so keyboard focus isn't lost when the alert (and its dismiss button) disappears. Pick the control that triggered the alert, or the next logical element. If unset and focus was inside the alert, handle focus yourself in | RefObject<HTMLElement | null> | — |
openWhether the alert is shown (controlled). Set with | boolean | — |
defaultOpenWhether the alert is shown initially (uncontrolled). | boolean | true |
onOpenChangeCalled with | (open: boolean) => void | — |
liveLive-region behavior. See | "off""polite""assertive" | "off" |
asRoot element. | "div""section""aside" | "div" |
sizePadding, type size, and icon size. | "sm""md""lg" | "md" |
radiusCorner rounding. | "none""xs""sm""md""lg""xl""2xl""pill" | "lg" |
Also accepts native <div> attributes, plus className, style and ref.
See what changed in each version in the Changelog.
Accessibility report
Alert targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.
axe-core audit (live)
Checking the examples above…
Lighthouse audit
Light mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Dark mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.
Built-in behavior
Keyboard
| Key | Action |
|---|---|
| Tab | Moves to the alert's action and close buttons; the alert itself isn't a tab stop. |
Roles and states
| Element | Role | States and properties |
|---|---|---|
| Alert (default) | none | Read in page order; not announced |
live="polite" | status | — |
live="assertive" | alert | — |
| Close button | button | aria-label ("Dismiss") |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck. | 2.1.1 (A), 2.1.2 (A) |
| Focus | Focus moves in a logical order, is always visible, and isn't hidden behind sticky headers. | 2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA) |
| Screen readers | Names, roles and states are announced correctly, and status changes are announced without moving focus. | 1.3.1 (A), 4.1.2 (A), 4.1.3 (AA) |
| Color | Meaning never depends on color alone; your own colors meet contrast in both modes. | 1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA) |
| Zoom and reflow | At 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed. | 1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA) |
| Pointer targets | Click and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap. | 2.5.8 (AA), 2.5.5 (AAA) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |