Alert
HkAlert is the static message strip: one glyph, an optional bold heading and a line of body copy, painted in the ink of one of four semantic variants. It lives in the flow of a page, a card or a form — it does not float, does not expire and does not take focus.
- Anything that appears on its own, slides in from a corner and goes away by itself is a transient notification, not an alert.
- An action that needs a decision before the page may continue belongs in a HkConfirmDialog or a HkModal, not in a message strip.
Import
;
use *; // Alert, AlertVariant, AlertSize
use *; // rsx!, VNode, Icon, MdiIcon
Variants
variant is the ink and the announcement tone at once: error (the default), warning, info and success. Each variant also picks its glyph — a triangle for error and warning, an information mark for info, a tick for success — so a message reads correctly even before the colour is registered.
The card was declined by the bank.
Your session expires in 5 minutes.
Nightly backups run at 02:00 UTC.
Your changes have been saved.
Title, sizes and banner
title adds a bold heading above the body. size steps the type from sm through md (default) to lg, and banner turns the strip into the full-width presentation that sits flush under a page header. padding overrides the box's own spacing with one of the shared container steps — none, xs, sm, md, lg — written to the same --hk-pad custom property every container consumes, so one stylesheet serves both renderers. The Rust example below shows the size step only: the padding field exists on the mirror (Option<HkPad>), but the HkPad type is not reachable through the documented use hikari_components::* plus prelude imports, so the example cannot spell it — a re-export gap worth fixing upstream, not in these pages.
We could not reach the server
Your draft is kept locally. Retry once the network is back.
Compact step
Dismissal and custom content
With closable the strip carries a ✕ on its trailing edge, which emits close. Vue dismisses the instance itself on press — there is no v-model, so showing it again means remounting it at the call site. The Rust mirror has no local state to hide behind: it keeps rendering while visible is true, fires on_close, and the host flips visible (or unmounts the alert) — that is the shape the second stage below shows.
The icon slot (Rust: the icon element prop) replaces the variant's glyph, and the default slot (Rust: body) replaces the message text.
A new version is available.
Import finished
312 rows added, 4 skipped.
Accessibility
- The root carries a live region unless you opt out: error and warning publish role="alert" with aria-live="assertive", info and success publish role="status" with aria-live="polite". Because the whole strip is one region, the heading and the body are announced together.
- A live region only announces content inserted or changed after it registers; an alert already present at mount is read in document order like static text. Mount the alert when the condition appears, which is also how the in-repo consumers use it.
- ownsLiveRegion={false} drops the role / aria-live pair while keeping the visuals — for an alert nested inside a container that already owns the region. Without the opt-out a nested alert would announce twice.
- Never rely on colour alone: the variant glyph carries the same meaning as the ink.
- The ✕ is a standard icon button with an accessible name (hikari::alert.close, falling back to "Close"), and it is the only focusable part of the strip.
API
Vue
Props
| Name | Type | Default | Required |
|---|---|---|---|
| variant | String as PropType<AlertVariant> | "error" | — |
| message | String | — | ✓ |
| title | String | undefined | — |
| closable | Boolean | false | — |
| banner | Boolean | false | — |
| size | String as PropType<AlertSize> | "md" | — |
| padding | String as PropType<HkPad> | undefined | — |
| ownsLiveRegion | Boolean | true | — |
Emits
| Event | Payload |
|---|---|
| close | — |
Rust
Props — Alert
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | AlertVariant | AlertVariant::Error | Semantic variant; also picks the default icon and the ink color. |
| message | String | "" | Body text (Vue: message, required). |
| title | Option<String> | None | Optional bold heading above the body (hk-alert-title). |
| closable | bool | false | Render the ✕ button; clicking hides this instance and fires AlertProps::on_close. |
| banner | bool | false | Full-width banner presentation (hk-alert-banner). |
| size | AlertSize | AlertSize::Md | Size step (hk-alert-{size}). |
| padding | Option<HkPad> | None | Shared container-padding override (--hk-pad; see utils::pad). |
| owns_live_region | bool | true | Mirror of the Vue ownsLiveRegion prop (default true): false drops the root's role/aria-live pair while keeping the visuals, for an alert nested inside a container that already owns the live region (the failed HkAuthHandoff card). |
| icon | Option<Element> | None | Icon slot: replaces the per-variant default icon. |
| body | Option<Element> | None | Body slot (Vue: the default slot). |
| visible | bool | true | Keep rendering the alert (Vue: the uncontrolled local dismissal flag; see the file-header delta — the host owns this on the Rust side). |
| on_close | Option<EventHandler<MouseEvent>> | None | Fired when the ✕ button is clicked; the host flips visible. |
| class | String | "" | — |
Related components
- HkSpinner — an inline busy indicator, without a message.
- HkEmptyState — the placeholder for a region that has no content yet, including its loading variant.
- HkLoadingVeil — the blocking overlay for a navigation-span wait.
- Button — the text action an alert often points at.
- HkConfirmDialog — asking before an irreversible step.