Alert
A message component for communicating status, feedback, warnings, errors, and important information.
Import Alert
Import Alert from Tavix:
import { Alert } from "tavix";Component API
<Alert
variant="info"
title
icon={true}
closable={false}
onClose
action
className=""
{...props}
>
Message
</Alert>Props
variant: Semantic message type:success,info,warning, orerror. Defaults toinfo.title: Optional heading displayed above the message.children: Message content displayed inside the alert.icon: Displays the variant icon whentrue. Defaults totrue.closable: Displays a close button whentrue. Defaults tofalse.onClose: Callback called when the close button is activated.action: Optional action content, such as a retry or undo button.className: Additional classes applied to the alert....props: Additional props forwarded to the root element.
Behavior
- Displays semantic styling based on
variant. - Uses an appropriate default icon for each variant when
iconistrue. - Renders
titlewhen provided. - Renders
childrenas the primary alert message. - Renders custom
actioncontent when provided. - Renders a close button when
closableistrue. - Calls
onClosewhen the close button is activated. - Does not hide itself automatically after
onClose; the parent controls visibility. - Uses
role="alert"for error alerts. - Uses
role="status"for non-error alerts.
Examples
Informational alert
<Alert variant="info" title="New update available">
Refresh the page to load the latest version.
</Alert>Success alert
<Alert variant="success" title="Saved">
Your changes were saved.
</Alert>
<Alert
variant="error"
title="Unable to save"
closable
onClose={handleClose}
action={<button type="button">Retry</button>}
>
Check your connection and try again.
</Alert>Warning alert
<Alert variant="warning" title="Review required">
Check these settings before continuing.
</Alert>Error alert
<Alert variant="error" title="Unable to save">
Check your connection and try again.
</Alert>Alert without an icon
<Alert variant="info" icon={false}>
This message is displayed without a leading icon.
</Alert>Dismissible alert
const [visible, setVisible] = useState(true);
{visible && (
<Alert
variant="success"
title="Changes saved"
closable
onClose={() => setVisible(false)}
>
Your preferences were updated.
</Alert>
)}Alert with an action
<Alert
variant="error"
title="Connection lost"
action={
<button type="button" onClick={retryConnection}>
Retry
</button>
}
>
We could not reach the server.
</Alert>Accessibility
- Error alerts use
role="alert"for immediate attention. - Informational, success, and warning alerts use
role="status". - The close button has an accessible label.
- Use a concise
titleand message so the alert is understandable when announced. - Provide accessible names and keyboard behavior for custom
actioncontent. - Do not rely on color or iconography alone to communicate the message type.
Notes
- Supported variants are
success,info,warning, anderror. icondefaults totrue.closableonly renders the close control; the parent must remove the alert.onClosedoes not automatically hide or remove the component.- Use
actionfor a follow-up command such as Retry, Undo, or View details. - Additional props are forwarded to the root alert element.