How to use
Alert surfaces contextual feedback inline with the content it relates to — a validation error under a form, a success message after a save, a warning banner at the top of a page. It renders with role="alert" so assistive technology announces it as soon as it appears, and unlike Toast it never leaves its place in the layout or auto-dismisses on its own.
import { Alert } from "oks-ui";The most common place to reach for Alert is right after something happens — a form submits, a request fails, a background job finishes. Keep a small piece of state for whichever case applies, render the matching Alert conditionally, and pass isClosable with an onClose handler that clears that state so the user can dismiss it once they've read it.
function SaveFeedback() {
const [status, setStatus] = useState<"success" | "error" | null>(null);
async function handleSave() {
try {
await fetch("/api/profile", { method: "PATCH" });
setStatus("success");
} catch {
setStatus("error");
}
}
return (
<div className="flex flex-col gap-3">
{status === "success" && (
<Alert
color="success"
title="Saved"
description="Your profile changes were saved."
isClosable
onClose={() => setStatus(null)}
/>
)}
{status === "error" && (
<Alert
color="danger"
title="Couldn't save"
description="Something went wrong. Try again."
isClosable
onClose={() => setStatus(null)}
/>
)}
<Button onPress={handleSave} color="primary">Save changes</Button>
</div>
);
}variant controls density, color controls meaning, and they're independent — pick both for the emphasis a message actually needs. solid (the default) fills the background with the color and reads as the most urgent; soft uses a translucent tint of the color, a good default for messages living inside a form or card where a solid block would compete with the rest of the page; bordered keeps just a colored edge and barely-there background, for messages that should be noticeable but not shout.
The seven color values (default, primary, secondary, info, success, warning, danger) each drive the built-in status icon automatically, so picking a success or danger color doesn't require also picking an icon — Alert already knows which one fits.
<Alert variant="solid" color="danger" title="Failed" description="The upload could not complete." />
<Alert variant="soft" color="warning" title="Heads up" description="You have unsaved changes." />
<Alert variant="bordered" color="info" title="Note" description="This setting applies to new members only." />isClosable adds a close button (and lets Escape dismiss it while it has focus) — reach for it on transient feedback like a save confirmation, where there's nothing left for the user to do but acknowledge it. Leave it off (the default) for a persistent alert the user needs to actually resolve, like a validation error still attached to an invalid field — closing it wouldn't fix the underlying problem, so removing the escape hatch keeps the message in front of them until the form is valid.
Alert supports both controlled and uncontrolled visibility. Pass isVisible yourself if you're already tracking the state elsewhere; otherwise just mount/unmount the Alert (as in the example above) and let onClose tell you when to unmount it.
Three optional slots sit around the title/description block for anything an inline text message alone can't cover. startContent renders above the icon/title/description row — useful for a small label or badge. actions renders directly below the description, for a button or two that respond to the alert ("Retry", "Undo", "View details"). endContent renders after actions, for something like a timestamp or a secondary link.
<Alert
color="danger"
title="Upload failed"
description="The file exceeded the 10 MB limit."
actions={
<Button size="sm" variant="soft" color="danger" onPress={retry}>
Try again
</Button>
}
isClosable
onClose={() => setShowError(false)}
/>Every color role has a sensible default icon baked in, so most usage never needs to touch it. When it does: pass icon with any ReactNode to replace it outright, hideIcon to remove the icon (and its wrapper) entirely, or hideIconWrapper to keep the icon but drop the circular background behind it — handy when the icon itself already reads clearly without extra framing.
All available props for Alert. See the full component page for an interactive playground.
| Prop | Type | Default | Description |
|---|---|---|---|
title | ReactNode | — | Alert title. |
description | ReactNode | — | Alert body content. |
icon | ReactNode | — | Overrides the default color-derived status icon. |
startContent | ReactNode | — | Content rendered before the title/description block. |
endContent | ReactNode | — | Content rendered after the title/description block. |
actions | ReactNode | — | Action buttons rendered below the description. |
title
ReactNode
Default: —
Alert title.
description
ReactNode
Default: —
Alert body content.
icon
ReactNode
Default: —
Overrides the default color-derived status icon.
startContent
ReactNode
Default: —
Content rendered before the title/description block.
endContent
ReactNode
Default: —
Content rendered after the title/description block.
actions
ReactNode
Default: —
Action buttons rendered below the description.
| Prop | Type | Default | Description |
|---|---|---|---|
color | "default" | "primary" | "secondary" | "info" | "success" | "warning" | "danger" | default | Semantic color, also picks the default status icon. |
variant | "solid" | "soft" | "bordered" | solid | Visual style variant. |
shadow | "none" | "xs" | "xs-sm" | "sm" | "md" | "lg" | none | Box-shadow depth. |
radius | "none" | "xs" | "xs-sm" | "sm" | "md" | "lg" | "full" | md | Border radius. |
size | "xs" | "xs-sm" | "sm" | "md" | "lg" | "xl" | md | Alert size. |
color
"default" | "primary" | "secondary" | "info" | "success" | "warning" | "danger"
Default: default
Semantic color, also picks the default status icon.
variant
"solid" | "soft" | "bordered"
Default: solid
Visual style variant.
shadow
"none" | "xs" | "xs-sm" | "sm" | "md" | "lg"
Default: none
Box-shadow depth.
radius
"none" | "xs" | "xs-sm" | "sm" | "md" | "lg" | "full"
Default: md
Border radius.
size
"xs" | "xs-sm" | "sm" | "md" | "lg" | "xl"
Default: md
Alert size.
| Prop | Type | Default | Description |
|---|---|---|---|
isVisible | boolean | — | Controlled visibility; uncontrolled defaults visible. |
isClosable | boolean | false | Shows a close button. |
hideIcon | boolean | false | Hides the status icon entirely. |
hideIconWrapper | boolean | false | Hides the icon's background wrapper, keeping the icon itself. |
closeButtonProps | Omit<ButtonHTMLAttributes<HTMLButtonElement>, "type"> | — | Extra props forwarded to the close button. |
isVisible
boolean
Default: —
Controlled visibility; uncontrolled defaults visible.
isClosable
boolean
Default: false
Shows a close button.
hideIcon
boolean
Default: false
Hides the status icon entirely.
hideIconWrapper
boolean
Default: false
Hides the icon's background wrapper, keeping the icon itself.
closeButtonProps
Omit<ButtonHTMLAttributes<HTMLButtonElement>, "type">
Default: —
Extra props forwarded to the close button.
| Prop | Type | Default | Description |
|---|---|---|---|
disableAnimation | boolean | false | Disables the enter/exit animation. |
disableAnimation
boolean
Default: false
Disables the enter/exit animation.
| Prop | Type | Default | Description |
|---|---|---|---|
onClose | () => void | — | Called when the close button is pressed. |
onVisibleChange | (isVisible: boolean) => void | — | Called whenever visibility changes. |
onClose
() => void
Default: —
Called when the close button is pressed.
onVisibleChange
(isVisible: boolean) => void
Default: —
Called whenever visibility changes.
| Prop | Type | Default | Description |
|---|---|---|---|
classNames | Partial<Record<AlertSlot, string>> | — | Per-slot class overrides. |
className | string | — | Class applied to the root element. |
style | CSSProperties | — | Inline styles for the root element. |
classNames
Partial<Record<AlertSlot, string>>
Default: —
Per-slot class overrides.
className
string
Default: —
Class applied to the root element.
style
CSSProperties
Default: —
Inline styles for the root element.