Display
Alert
An inline message in the page: something saved, something failed, something to know before going on. It has a title, an optional description and action, and a close button when you pass onDismiss. Destructive and warning alerts are spoken at once (role="alert"); the others politely (role="status").
In Spoonjoy
Spoonjoy, a recipe app, is built with Ouro HX (how).
In its source: app/components/recipe/IngredientParseInput.tsx · app/routes/recipes.$id.edit.tsx · app/routes/recipes.$id.steps.$stepId.edit.tsx
Install
Once per app, with Tailwind CSS v4 and an @/* path alias (Ouro HX is built on Base UI, so --base base; skip -t in an existing app):
npx shadcn@latest init --base base --preset nova --yes --no-monoreponpx shadcn@latest add ourostack/ouro-ui/ouro-base#v1.2.13Then the component. From v0.8.0 it installs only the helpers it imports and never touches your stylesheet (Installing):
npx shadcn@latest add ourostack/ouro-ui/alert#v1.2.13Or, with the @ouro namespace set up:
npx shadcn@latest add @ouro/ouro-base @ouro/alertIts tests, stories and Playwright spec are optional. They need Vitest 4.1.11 or later, and from v0.8.0 never change a version your app has (Testing):
npx shadcn@latest add ourostack/ouro-ui/alert#v1.2.13 ourostack/ouro-ui/alert-tests#v1.2.13import { Alert } from "@/components/ouro/alert/alert";Paths use shadcn's default @/ alias; the CLI rewrites them to yours.
Example
<Alert tone="success" title="Recipe saved" />
<Alert
tone="destructive"
title="Couldn't save"
description="Check your connection and try again."
action={<Button size="sm" onClick={retry}>Try again</Button>}
onDismiss={() => setError(null)}
/>Usage
In and around forms, use Alert for a message that belongs to neither a field nor the form as a whole: a reorder or a deletion the server refused, a step that could not be parsed. Render it where the action was taken, with action for the way out.
Use instead when
- Use
Toastinstead for a brief message that disappears by itself,ConfirmDialogto ask before a destructive action, andField'serrorfor a message about one field. - Use
Form'serrorsinstead for what a submit returned: a field's name as the key puts the message under that field, and theformkey shows it at the top of the form.
Props
Type: AlertProps.
action- Type:
ReactNode - A control under the description, usually a small Button:
action={<Button size="sm">Retry</Button>}. className- Type:
string - Layout only: margins, width, grid placement (
mt-4). Appearance classes warn in development; usetone. description- Type:
ReactNode - More detail, or what to do next, under the title.
dismissLabel- Type:
string - Default:
"Dismiss" - The close button's accessible name, for other languages.
icon- Type:
AlertIcon | null - The icon at the start, as a component:
icon={WifiOffIcon}. Each tone has its own by default;nullshows none. onDismiss- Type:
(() => void) - Shows a close button that calls this. Remove the alert from your state in it. When the alert goes, keyboard focus moves to the next control after it, or to the one before it when nothing follows, so it is not lost to the page.
ref- Type:
Ref<HTMLDivElement> - Reaches the rendered element.
title(required)- Type:
ReactNode - What happened, in a few words: "Recipe saved", "Couldn't save". Required, so every alert says what it is about.
tone- Type:
"primary" | "secondary" | "destructive" | "success" | "warning" - Default:
"secondary" - Color role from the theme, which also sets how urgently screen readers hear it:
destructiveandwarningarerole="alert"(spoken at once), the othersrole="status"(spoken politely).primaryis for information,secondaryfor a neutral note. shadcn'svariant="destructive"istone="destructive".
Native attributes
Also accepts the attributes in React's HTMLAttributes (id, aria-*, event handlers), passed to the rendered element, except those named on this page.
Don't use
These are not props. Passing one fails the type check with the fix in the error, and in development a console message names the fix.
children: Not a prop. Alert takestitleanddescription:<Alert title="…" description="…">.onClose: Not a prop. Ouro UI usesonDismiss:<Alert onDismiss={() => setOpen(false)}>.severity: Not a prop. Ouro UI usestone:<Alert tone="destructive">.status: Not a prop. Ouro UI usestone:<Alert tone="primary">.variant: Not a prop. Ouro UI usestone:<Alert tone="destructive">.
className is for layout only
Pass margins, width and grid placement (mt-4, w-full, col-span-2). Your classes always win over Ouro UI's: Alert merges className last with cn (tailwind-merge), so a class that conflicts with its own replaces it.layout-classes
Appearance comes from props, not classes. In development, a class that sets appearance logs one warning per component instance, naming the prop to use instead. A class sets appearance when, after its variants (hover:, sm:) and any ! are removed, it starts with bg-, text-, border-, rounded-, shadow-, font-, ring-, from-, via-, to-, fill- or stroke-, or is border, rounded, shadow or ring, or has a dark: variant. Text wrapping, overflow and table layout classes (text-wrap, text-ellipsis, border-collapse) are layout and do not warn.
Alignment classes (text-center) warn too: set alignment on a parent element.
Types
AlertIcon
An icon component, such as one from lucide-react or @heroicons/react.
type AlertIcon = ComponentType<SVGProps<SVGSVGElement>>;Claim sources
- layout-classes: test:registry/ouro/components/ouro/alert/alert.test.tsx::Alert > forwards a ref and lets app layout classes win
verify:testExists(registry/ouro/components/ouro/alert/alert.test.tsx::Alert > forwards a ref and lets app layout classes win)