Inline Alert
A message in the page next to what it is about. Five kinds on a white or tinted fill, a title, text, up to two actions and a close button.
Version 0.4.1 ·
Installation
bunx --bun shadcn@latest add @dga/inline-alertUsage
import { Button } from "@/components/ui/button";
import { InlineAlert } from "@/components/ui/inline-alert";
export function DocumentsNeeded() {
return (
<InlineAlert
variant="info"
title="Documents required"
actions={<Button size="sm">Attach document</Button>}
>
Attach the lease before you submit.
</InlineAlert>
);
}Use an Inline Alert for a message that belongs to one place: a form that has a problem, a card that needs a step, a section with a notice. It is part of the page, so it does not move or disappear by itself. For the whole page use a Notification; for something that just happened use a Toast. Give it a short title, one or two sentences of text, and at most two actions: the main one first. tinted colours the fill and text in the kind's colour; the default is a white card with a coloured bar.
Anatomy
- Alert (
role="status", orrole="alert"forwarninganddestructive): radius-md, a 1px border, padding 16 by 24px. - Bar: 8px on the start side, in the kind's 400 colour.
- Icon, title and text.
- Actions under the text (at most two) and a close button on the end side.
Examples
White and tinted
The five kinds on a white fill (left) and tinted (right). The info and warning alerts can be dismissed; the success and destructive ones have actions.
Without an icon and dismissed
hideIcon removes the status icon: the bar and the title still carry the kind. A destructive or warning alert is announced at once. After it is dismissed onDismiss runs and nothing is rendered in its place.
RTL
The bar and the icon are on the right, the close button on the left, and the actions start on the right. The alert is as wide as its container.
Accessibility
| Key | Action |
|---|---|
| Tab | Moves focus through the actions, then to the close button. |
| Enter | Presses the focused button or link. |
| Space | Presses the focused button. |
- A live region:
destructiveandwarninghaverole="alert"and interrupt; the rest arerole="status". Focus does not move. Mount it when it applies so it is announced. - The kind is shown by an icon and the title, not by the bar's colour alone. Title and text are 4.5:1 and icons 3:1 or better on the white and tinted fills, in light and dark.
- The close button has an accessible name (
dismissLabel) and a 2px focus outline.
API Reference
InlineAlert
A message inside the page next to what it is about (DGA: Inline Alert): a form, a card, a section. A coloured bar on the start side and an icon carry the kind, so colour is never the only cue. `destructive` and `warning` are announced at once (`role="alert"`), the others politely (`role="status"`). Mount it when it applies so it is announced.
| Prop | Type | Default |
|---|---|---|
"neutral" | "destructive" | "warning" | "success" | "info"Kind: `neutral`, `info`, `success`, `warning` or `destructive`. | "neutral" | |
| ||
booleanTinted fill and text in the kind's colour instead of white. | false | |
| ||
string | number | bigint | boolean | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | Promise<AwaitedReactNode>The short heading of the alert. | No default | |
| ||
booleanHides the status icon. | No default | |
| ||
string | number | bigint | boolean | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | Promise<AwaitedReactNode>Buttons or links under the text (at most two). | No default | |
| ||
() => voidCalled after the alert is dismissed. | No default | |
| ||
booleanShows the close button. The alert hides itself, then calls `onDismiss`. | No default | |
| ||
stringAccessible name of the close button. Translate it on Arabic pages. | "Dismiss" | |
| ||
Also accepts the props of the element it renders.
Deviations from DGA
- The neutral bar is
border-neutral-primary; DGA draws it white on a white alert, so it is invisible. - In Figma the tinted info and warning alerts with a close button swap the kind's icon for a plain one. The icon is always the kind's, so adding a close button changes nothing else.
| Change | Reason |
|---|---|
Inline Alert: icon colour and neutral bar | The icon should not change when a close button is added, and a white bar on a white alert is not there. |
Contrast
114 pairs checked · all pass WCAG 2.1 AAShow 37 statesHide
| Variant / state | Light | Dark |
|---|---|---|
| neutral / title | 14.53:1 AAA | 14.42:1 AAA |
| neutral / text | 10.17:1 AAA | 10.95:1 AAA |
| neutral / icon | 18.09:1 3:1 | 14.42:1 3:1 |
| info / title | 14.53:1 AAA | 14.42:1 AAA |
| info / text | 10.17:1 AAA | 10.95:1 AAA |
| info / icon | 5.98:1 3:1 | 8.98:1 3:1 |
| success / title | 14.53:1 AAA | 14.42:1 AAA |
| success / text | 10.17:1 AAA | 10.95:1 AAA |
| success / icon | 5.69:1 3:1 | 9.82:1 3:1 |
| warning / title | 14.53:1 AAA | 14.42:1 AAA |
| warning / text | 10.17:1 AAA | 10.95:1 AAA |
| warning / icon | 5.42:1 3:1 | 10.27:1 3:1 |
| error / title | 14.53:1 AAA | 14.42:1 AAA |
| error / text | 10.17:1 AAA | 10.95:1 AAA |
| error / icon | 6.57:1 3:1 | 8.18:1 3:1 |
| neutral tinted / text | 14.17:1 AAA | 15.87:1 AAA |
| neutral tinted / icon | 17.64:1 3:1 | 15.87:1 3:1 |
| neutral tinted / close icon | 17.64:1 3:1 | 15.87:1 3:1 |
| neutral tinted / focus ring | 17.64:1 3:1 | 17.49:1 3:1 |
| info tinted / text | 5.70:1 AA | 9.30:1 AAA |
| info tinted / icon | 5.70:1 3:1 | 9.30:1 3:1 |
| info tinted / close icon | 17.23:1 3:1 | 14.93:1 3:1 |
| info tinted / focus ring | 17.23:1 3:1 | 16.45:1 3:1 |
| success tinted / text | 5.54:1 AA | 10.01:1 AAA |
| success tinted / icon | 5.54:1 3:1 | 10.01:1 3:1 |
| success tinted / close icon | 17.63:1 3:1 | 14.71:1 3:1 |
| success tinted / focus ring | 17.63:1 3:1 | 16.20:1 3:1 |
| warning tinted / text | 5.29:1 AA | 10.71:1 AAA |
| warning tinted / icon | 5.29:1 3:1 | 10.71:1 3:1 |
| warning tinted / close icon | 17.66:1 3:1 | 15.03:1 3:1 |
| warning tinted / focus ring | 17.66:1 3:1 | 16.56:1 3:1 |
| destructive tinted / text | 6.39:1 AA | 8.59:1 AAA |
| destructive tinted / icon | 6.39:1 3:1 | 8.59:1 3:1 |
| destructive tinted / close icon | 17.60:1 3:1 | 15.14:1 3:1 |
| destructive tinted / focus ring | 17.60:1 3:1 | 16.68:1 3:1 |
| close icon | 18.09:1 3:1 | 14.42:1 3:1 |
| focus ring | 18.09:1 3:1 | 15.89:1 3:1 |
Text needs 4.5:1, icons and focus rings 3:1. Disabled states are exempt. Full contrast report