Skip to content

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 ·

Inline Alert

Installation

bunx --bun shadcn@latest add @dga/inline-alert

Usage

page.tsx
tsx
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", or role="alert" for warning and destructive): 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.

White and tinted

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.

Without an icon and dismissed

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.

LTR (English)
RTL (Arabic)

Accessibility

KeyAction
TabMoves focus through the actions, then to the close button.
EnterPresses the focused button or link.
SpacePresses the focused button.
  • A live region: destructive and warning have role="alert" and interrupt; the rest are role="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.

InlineAlert props
PropTypeDefault
"neutral" | "destructive" | "warning" | "success" | "info"

Kind: `neutral`, `info`, `success`, `warning` or `destructive`.

"neutral"
boolean

Tinted 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
boolean

Hides 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
() => void

Called after the alert is dismissed.

No default
boolean

Shows the close button. The alert hides itself, then calls `onDismiss`.

No default
string

Accessible 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.
ChangeReason
Inline Alert: icon colour and neutral barThe icon should not change when a close button is added, and a white bar on a white alert is not there.

View all 1 deviations for this component

Contrast

114 pairs checked · all pass WCAG 2.1 AAShow 37 states
Variant / stateLightDark
neutral / title14.53:1 AAA14.42:1 AAA
neutral / text10.17:1 AAA10.95:1 AAA
neutral / icon18.09:1 3:114.42:1 3:1
info / title14.53:1 AAA14.42:1 AAA
info / text10.17:1 AAA10.95:1 AAA
info / icon5.98:1 3:18.98:1 3:1
success / title14.53:1 AAA14.42:1 AAA
success / text10.17:1 AAA10.95:1 AAA
success / icon5.69:1 3:19.82:1 3:1
warning / title14.53:1 AAA14.42:1 AAA
warning / text10.17:1 AAA10.95:1 AAA
warning / icon5.42:1 3:110.27:1 3:1
error / title14.53:1 AAA14.42:1 AAA
error / text10.17:1 AAA10.95:1 AAA
error / icon6.57:1 3:18.18:1 3:1
neutral tinted / text14.17:1 AAA15.87:1 AAA
neutral tinted / icon17.64:1 3:115.87:1 3:1
neutral tinted / close icon17.64:1 3:115.87:1 3:1
neutral tinted / focus ring17.64:1 3:117.49:1 3:1
info tinted / text5.70:1 AA9.30:1 AAA
info tinted / icon5.70:1 3:19.30:1 3:1
info tinted / close icon17.23:1 3:114.93:1 3:1
info tinted / focus ring17.23:1 3:116.45:1 3:1
success tinted / text5.54:1 AA10.01:1 AAA
success tinted / icon5.54:1 3:110.01:1 3:1
success tinted / close icon17.63:1 3:114.71:1 3:1
success tinted / focus ring17.63:1 3:116.20:1 3:1
warning tinted / text5.29:1 AA10.71:1 AAA
warning tinted / icon5.29:1 3:110.71:1 3:1
warning tinted / close icon17.66:1 3:115.03:1 3:1
warning tinted / focus ring17.66:1 3:116.56:1 3:1
destructive tinted / text6.39:1 AA8.59:1 AAA
destructive tinted / icon6.39:1 3:18.59:1 3:1
destructive tinted / close icon17.60:1 3:115.14:1 3:1
destructive tinted / focus ring17.60:1 3:116.68:1 3:1
close icon18.09:1 3:114.42:1 3:1
focus ring18.09:1 3:115.89:1 3:1

Text needs 4.5:1, icons and focus rings 3:1. Disabled states are exempt. Full contrast report