Alert

An inline status message with an intent.

  • Composed
  • New in 0.1
import { Alert, alertPrimitive } from "nitro-ui-sdk/alert";
HeroUI Native
Alert
Expo UI
No counterpart
  • Alert example screen, light appearance
    Light
  • Alert example screen, dark appearance
    Dark
On this page

Alert is an inline callout for a result the person should see next to the work, not later in a toast. Use it for a saved confirmation, a warning, or a failure that stays on the page. Put an optional action under the copy and a dismiss control when the person can put it away.

Anatomy

<Alert.Root title="Library saved" description="Your changes are on this device." intent="success">
  <Alert.Message>
    <Alert.Indicator />
    <Alert.Title />
    <Alert.Description />
  </Alert.Message>
  <Alert.Action />
  <Alert.CloseButton />
</Alert.Root>
Part Description
Root The callout. Renders nothing while it is closed.
Message Groups the title and description as one alert.
Indicator The intent icon.
Title The short heading.
Description The supporting sentence.
Action Slot for one action, such as a button.
CloseButton Dismiss control. Rendered only when onClose is set.

The default layout keeps the message and the close button as separate accessibility elements, so VoiceOver can reach Dismiss.

Usage

import { Alert } from "nitro-ui-sdk/alert";

export function Saved() {
  return (
    <Alert.Root
      title="Library saved"
      description="Your changes are on this device."
      intent="success"
      variant="soft"
    />
  );
}

Variants and sizes

intent is default, accent, success, warning, or danger. variant is soft (default), solid, or outline. The only size is md.

Icons: info.circle.fill, sparkles, checkmark.circle.fill, exclamationmark.triangle.fill, and exclamationmark.octagon.fill. Pass symbol to replace the icon.

<Alert.Root title="Could not upload" intent="danger" variant="outline" />

States

open defaults to true for an uncontrolled alert (defaultOpen). A closed alert renders nothing. live announces the message once when the alert appears, and again if it closes and comes back. live defaults to false.

Controlled

Pass open when the parent owns visibility. onClose runs first. preventDefault() refuses the dismiss. A controlled alert stays open until the parent sets open to false.

const [open, setOpen] = useState(true);

<Alert.Root
  title="Library saved"
  description="Your changes are on this device."
  intent="success"
  open={open}
  onClose={() => setOpen(false)}
/>

A second dismiss while the alert is already closed is disabled.

Liquid Glass

Alert does not draw Liquid Glass. Soft, solid, and outline fills use opaque semantic colors.

Props

Root

Prop Type Default Description
title string — Heading and accessible name. Required.
description string — Supporting sentence.
intent "default" | "accent" | "success" | "warning" | "danger" "default" Color and default icon.
variant "soft" | "solid" | "outline" "soft" Fill treatment.
symbol string from the intent SF Symbol name.
live boolean false Announces when the alert appears.
open boolean — Controlled visibility.
defaultOpen boolean true Initial visibility when open is omitted.
closeLabel string "Dismiss" Accessible name of the close control.
action ReactNode — Optional action, placed under the copy.
onClose (details) => void — Shows the close control. May call preventDefault().
onAnnounce (message: string) => void — Replaces the platform announcement.
styles AlertStyles — Per-part style resolvers.
api Controller<AlertActions> — Attached controller.
agentId string — Stable agent id.
layout layout — Extra layout merged onto the root.

Controller API

import { alertPrimitive } from "nitro-ui-sdk/alert";

const api = alertPrimitive.createApi();
api.current?.dismiss("api");
api.current?.getState();
Action Signature Result
dismiss (source?) => ChangeStatus accepted and closed, requested while controlled, refused after preventDefault, or disabled when already closed.
getState () => AlertState open, live, and intent.

An accepted dismissal from a touch on CloseButton plays a light impact. For a controlled alert, the impact follows the owner’s commit to open={false}.

Styles

The resolver receives tokens, variant, size ("md"), and state.

<Alert.Root
  title="Library saved"
  intent="success"
  styles={{
    title: ({ tokens }) => ({ text: { color: tokens.colors.foreground } }),
  }}
/>

Accessibility

Message is role alert, named by title, with description as the value. Its visual content is hidden from TalkBack so the message is read once. Place the close button and any actions outside Message so they remain separately accessible. The close button uses closeLabel and has a 44 point target. When live is true, the title and description are announced once on appearance.

Agent API

Action Arguments Notes
dismiss none Available on an open alert with onClose. For a controlled alert, the handler must set open to false to accept the dismissal.

An open alert without onClose is read-only for agents. When composing custom children for a dismissible alert, include Alert.CloseButton outside Alert.Message.

Role alert. The name is the title and the text is the description.

Platform notes

iOS Android
Drawing Composed. The icon and the close mark are SF Symbols. Composed. Off iOS the indicator and the close mark are text glyphs (i, !, ✓, ×) inside the same accessible names.
Haptics Light impact on an accepted touch dismiss. No haptic call.
Verification Exercised by the iOS harness on the lanes simulator. No Kotlin was added for this family.