Skip to content

Alert

An inline feedback banner on the shared intent scale, with an optional heading and dismiss button. Announcement semantics are opt-in, and the Form error summary is built from one.

Import

import { Alert } from "@hyzer-labs/ui"

Demo

Alert vs Banner

Use Alert for an inline message that sits next to the thing it describes. For a solid, full-width announcement at page level, one you can pin to the top or bottom, use Banner instead.

The intent vocabulary plus the neutral default. The Form error summary renders as intent="danger" automatically.

Course note

Hole 7 tee pads were resurfaced this week.

League night

Tags round starts at 5:30pm on Thursday.

Doubles signup

Random-draw doubles opens 30 minutes early.

Course closed

Lightning in the area. Clear the course now.

High winds

Gusts over 30mph expected after 2pm.

Round saved

Your scorecard was synced to the league.

Cart friendly

The back nine is paved end to end.
<Alert title="Course note">Hole 7 tee pads were resurfaced this week.</Alert>
<Alert intent="danger" title="Course closed">Lightning in the area. Clear the course now.</Alert>
<Alert intent="warning" title="High winds">Gusts over 30mph expected after 2pm.</Alert>
<Alert intent="success" title="Round saved">Your scorecard was synced to the league.</Alert>

Props

NameTypeDefaultNote
childrenSnippetRequired. The alert body.
titlestring | SnippetOptional heading; labels the alert via aria-labelledby.
headingLevel2 | 3 | 4 | 5 | 63An alert is nearly always a callout inside a section rather than a section of its own, so the default keeps it below your page headings. Raise or lower it to match the surrounding document.
intentIntent'neutral'See Foundation → Colors & Intent.
rounded'none' | 'sm' | 'md' | 'lg' | 'full''md'The shared Rounded scale — 1:1 with the --hz-radius-* tokens.
iconSnippetDecorative; rendered aria-hidden.
onDismiss() => voidRenders the dismiss button. Visibility is your state — the Alert never hides itself.
dismissLabelstring'Dismiss'
classstringMerged after the hz-alert class.

Theme hooks

What this component promises your CSS. The reference theme styles exactly these — from @layer hz-theme, so your unlayered rules win. See Styling Components for the how.

Root class: .hz-alert

Data attributes

HookValuesStyles
data-intent'neutral' | any registered intentDrives the accent bar, tint, and title colour. Spans the intent registry, so an intent you register lands here too.
data-rounded'none' | 'sm' | 'md' | 'lg' | 'full'1:1 with the --hz-radius-* scale. Default md.
data-dismissiblepresent when dismissibleMarks the dismissible form. Always stamped so you can target it, though the reference theme ships no rule for it.

Custom properties

HookValuesStyles
--hz-alert-tint<percentage> — 10% light, 22% darkHow strongly the intent colour mixes into the surface. Retuning it means re-checking the soft pairings on Contrast & Accessibility.
--hz-alert-border-width<length> — default var(--hz-border-width-heavy)Thickness of the inline-start accent bar. Defaults to the heaviest border-width token; override with any length or a lighter token.

Part classes

HookValuesStyles
.hz-alert-iconchild elementThe intent icon.
.hz-alert-bodychild elementTitle and content wrapper.
.hz-alert-titlechild elementThe heading, at your headingLevel.
.hz-alert-contentchild elementThe message body.
.hz-alert-dismisschild elementThe dismiss button.

Accessibility

A statically rendered Alert is plain content: no role, no live region. The optional title names it via aria-labelledby.

For alerts inserted after load, pass role="status" (polite) or role="alert" (assertive, use sparingly) via the rest props. A live role on static content is dead weight, so it's never a default.

The dismiss button is a real labeled <button>. Dismissal is your state change, so consider where focus should land.

There is deliberately no Toast component. A timed self-dismissing overlay is hard to make accessible. Under WCAG 2.2.1 the timing has to be adjustable, extendable, or pausable. A message that vanishes on its own often goes unannounced as well. The library prefers dismissal the reader chooses, so content never disappears out from under them. An inline Alert with role="status" covers the need accessibly.

References: APG Alert pattern · MDN: alert role