Skip to the content
human-kit design
56 — Feedback

Alert

A message that stays in the page, with a mark for its kind and, if it needs them, an action and a close.

Consent form missing

The patient has not signed the consent for the frozen transfer.

Installation

pnpm dlx @human-kit/design add alert
npx @human-kit/design add alert
yarn dlx @human-kit/design add alert
bunx @human-kit/design add alert

The command copies the files to src/lib/components/ui/alert. It also installs the packages that the files import.

Usage

<script lang="ts">
	import * as Alert from '$lib/components/ui/alert';
</script>

<Alert.Root tone="warning" title="Consent form missing">
	It is needed before the procedure.
</Alert.Root>

Examples

In answer to the user

A message that appears after an action goes inside an element with role="status" that is already in the page, so a screen reader hears it arrive. Use role="alert" instead only for what cannot wait.

Guidelines

  • Use an alert for what the page says about itself and stays true while the page is open: a missing form, an account on hold. For what just happened, use a toast.
  • Use outline, a white card with a coloured mark, for most messages. Use soft, the tone’s fill and line, for the one that must be seen before the rest of the page.
  • Pick the tone from what the message means: danger for an error that blocks, warning for one that will, success for a task done, info and neutral for the rest.
  • Give a title that says the matter in a few words, and the words under it that say what to do. Keep actions to one or two small buttons.
  • Pass onDismiss only when the message can go away without being dealt with.

Accessibility

  • The alert has no live role of its own: a message in the page from the start is read with the page, not announced once more on each change.
  • For a message shown in answer to the user, give it a live region: role="status", or role="alert" when it is urgent.
  • The mark is hidden from screen readers; the title and the words say the tone. Do not rely on the colour alone.
  • The close button is a <button> named by dismissLabel, "Dismiss" by default. After it closes the alert, move the focus somewhere that makes sense.

API reference

PropTypeDefault
variant'outline' | 'soft'

A white card, or the tone’s fill and line.

'outline'
tone'neutral' | 'info' | 'success' | 'warning' | 'danger'

What kind of message it is. It sets the mark, and the fill of soft.

'neutral'
titlestring

The first line, in full ink.

—
childrenSnippet

The words under the title.

—
actionsSnippet

Buttons under the words. Use small ones: <Button.Root size="sm">.

—
iconSnippet

Your own mark in place of the tone’s.

—
onDismiss() => void

Called by the close button. Without it, there is no close button.

—
dismissLabelstring

The name of the close button, read aloud.

'Dismiss'

Plus every attribute of a <div>, but title, which is the heading of the alert here.