Skip to the content

Kongens Nytorv

Metro M1, M2 and M3.

Could not load departures

The real-time feed stopped answering at 08:02. Departures show the timetable only.

Variants and states

Rest
Neutral

Could not load departures

The real-time feed stopped answering at 08:02. Departures show the timetable only.
Success

Could not load departures

The real-time feed stopped answering at 08:02. Departures show the timetable only.
Warning

Could not load departures

The real-time feed stopped answering at 08:02. Departures show the timetable only.
Danger

Could not load departures

The real-time feed stopped answering at 08:02. Departures show the timetable only.
Info

Could not load departures

The real-time feed stopped answering at 08:02. Departures show the timetable only.
Neutral
  • Rest

    Could not load departures

    The real-time feed stopped answering at 08:02. Departures show the timetable only.
Success
  • Rest

    Could not load departures

    The real-time feed stopped answering at 08:02. Departures show the timetable only.
Warning
  • Rest

    Could not load departures

    The real-time feed stopped answering at 08:02. Departures show the timetable only.
Danger
  • Rest

    Could not load departures

    The real-time feed stopped answering at 08:02. Departures show the timetable only.
Info
  • Rest

    Could not load departures

    The real-time feed stopped answering at 08:02. Departures show the timetable only.

Props

NameTypeDefaultDescription
color'neutral' | 'success' | 'warning' | 'danger' | 'info''neutral'The intent: what the message means. neutral for a plain notice, success for something that went well, warning for something to take care with, danger for something that failed or stops the task, info for something worth knowing; always in words that say it too. Set on the root as data-color
titleReactNode—The message in a few words, above the sentences: "Signal fault at Danshøj". Replaces the HTML title attribute
childrenReactNode—What is happening and how sure we are, in plain sentences: "Trains between Flintholm and Ny Ellebjerg run slower than planned. We don't know yet when the fault will be fixed."
iconReactNode—Replaces the intent's icon, for the eye only: it is hidden from screen readers. null or false shows no icon; left out, the intent's own shows, and neutral has none. It renders at 13 px, icon.size.325, so give an icon drawn on the 14 px grid, or set --perron-icon-size to its step's icon.size.* through slotProps.icon
actionReactNode—What the person can do about it, such as a small outline Button "Try again" or a LinkButton "Show on map", below the sentences
onClose(event: MouseEvent, reason: 'close-press', details: AlertCloseDetails) => void—Called when the close button is pressed, with the reason 'close-press'. Given, it shows the close button; Alert never hides itself, so remove it here and move focus to the element before it
closeLabelstringThe locale'sOverrides "Close", the close button's name
slotProps{ icon?: ComponentProps<"div", {}, HTMLProps> | undefined; content?: ComponentProps<"div", {}, HTMLProps> | undefined; title?: ComponentProps<"p", {}, HTMLProps> | undefined; description?: ComponentProps<"div", {}, HTMLProps> | undefined; action?: ComponentProps<"div", {}, HTMLProps> | undefined; close?: Omit<DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "children" | "disabled"> | undefined; }—Props for each part: icon, content, title, description, action, close.
color'neutral' | 'success' | 'warning' | 'danger' | 'info', default 'neutral'
The intent: what the message means. neutral for a plain notice, success for something that went well, warning for something to take care with, danger for something that failed or stops the task, info for something worth knowing; always in words that say it too. Set on the root as data-color
titleReactNode, default —
The message in a few words, above the sentences: "Signal fault at Danshøj". Replaces the HTML title attribute
childrenReactNode, default —
What is happening and how sure we are, in plain sentences: "Trains between Flintholm and Ny Ellebjerg run slower than planned. We don't know yet when the fault will be fixed."
iconReactNode, default —
Replaces the intent's icon, for the eye only: it is hidden from screen readers. null or false shows no icon; left out, the intent's own shows, and neutral has none. It renders at 13 px, icon.size.325, so give an icon drawn on the 14 px grid, or set --perron-icon-size to its step's icon.size.* through slotProps.icon
actionReactNode, default —
What the person can do about it, such as a small outline Button "Try again" or a LinkButton "Show on map", below the sentences
onClose(event: MouseEvent, reason: 'close-press', details: AlertCloseDetails) => void, default —
Called when the close button is pressed, with the reason 'close-press'. Given, it shows the close button; Alert never hides itself, so remove it here and move focus to the element before it
closeLabelstring, default The locale's
Overrides "Close", the close button's name
slotProps{ icon?: ComponentProps<"div", {}, HTMLProps> | undefined; content?: ComponentProps<"div", {}, HTMLProps> | undefined; title?: ComponentProps<"p", {}, HTMLProps> | undefined; description?: ComponentProps<"div", {}, HTMLProps> | undefined; action?: ComponentProps<"div", {}, HTMLProps> | undefined; close?: Omit<DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "children" | "disabled"> | undefined; }, default —
Props for each part: icon, content, title, description, action, close.

Use it

import { Alert } from '@mylder/perron'

Ask your agent

search_docs({ query: "Alert" })

Keyboard and ARIA

The alert takes no focus and has no keys of its own. The caller's action and the close button are reached in reading order; Esc does nothing, since an inline message is not a layer that closes (Accessibility, Keys).

KeyDoesFrom
TabMoves to the action's first control, then to the close button, after the sentencesThe browser
Shift+TabMoves back through them, and out to whatever came before the alertThe browser
Enter, SpaceOn the close button, presses it: onClose is called with the reason 'close-press'The browser; Perron calls onClose
ElementRoleAccessible name fromStates announced
rootstatus, a polite live region, unless the caller passes another roleNone: a status needs no nameNone
iconHidden: aria-hidden="true"NoneNone
titleParagraph, or a heading when slotProps.title.render makes it oneIts text, from titleNone
descriptionNone (generic div)NoneNone
actionNone (generic div); the caller's controls carry their own rolesThe caller's controls' own namesTheirs
closebuttonThe owned "Close", or closeLabel, in the VisuallyHidden partNone

The root carries role="status" by default, for every color, unless the caller gives a role, so a caller can pass role="alert" for a danger message that stops the task the person is in; it is never alert by default. Accessibility asks for a polite live region that announces changes of state only, a status on a message present when the page loads is not read out and does no harm, a message whose words change while it stays mounted is read once, politely, and an alert on every danger message would interrupt whatever the person is hearing. A message added to the page with its words already in it is not reliably announced by a status (DataStatePanel keeps its region mounted for that reason), so CR-8 tells the caller what to do when one must be heard as it appears.

Alert adds no hidden word for its intent, such as "Warning" before the title; the caller's words say what the colour and the icon show, as Tag's and EmptyState's do: content design asks for plain sentences that say what is happening, a title such as "Could not load departures" already says it failed, and a fixed word before it would be read on every message, in four languages, and repeat what the sentence says ("Warning: Signal fault …").

What axe won't catch, from the contract, each with how this component meets it:

  • Everything the eye is told, the ear is told, for every shape each prop accepts: the colour, the tint and the icon repeat what the caller's words say, and the icon is aria-hidden; the color JSDoc and CR-2 ask for words that say the intent, and the stories hold to it. In forced colours the tint goes, and the edge, the icon's shape and the words stay.
  • Every landmark and named region has an accessible name: none here; a status is a live region, not a landmark, and needs no name.
  • Every default label can be overridden: closeLabel.
  • Every shape the type accepts renders, in every variant: title, children, icon and action each render a string, an element and an array; description and action are divs, so block content such as a list is valid inside them, and the title takes phrasing content as a p or a heading does; icon as null or false renders no icon part (CR-3).
  • A hidden copy kept for animation is aria-hidden, and a collapsed region is inert: none here; nothing animates or collapses.
  • Native semantics first: a p for the title, made a native h2 to h6 through render; the close button is a native <button type="button">; the action holds the caller's own button or a href; the one ARIA is the root's role="status", which no element says.
  • Focus moves in reading order and returns on close: the action follows the sentences and the close button comes last, in the DOM and in the tab order; Alert never moves focus when it appears, and once the caller removes it in onClose the caller moves focus to the element before it (CR-7).
  • Every target is at least size.target-min square: the close button is size.control, 34 px; the action's targets are the caller's components, a small Button size.button-sm.
  • Loops stop when the system asks for less motion: none here; nothing moves.

Owned strings

Alert owns one word, the close button's name, and reuses the key en.ts has, whose JSDoc already reads "A button that closes a dialog, panel or notice." Every other word comes from the caller, through title, children and action, and the icon is hidden from screen readers.

KeyEnglishOverrideSeen or heard where
close"Close"closeLabelclose, heard as the button's name through the VisuallyHidden part, only when onClose is given; the key en.ts has

Do and don't

For a caller using the component, with the reason. Each row is a rule: a must row's Don't is never right, a should row's needs a reason, and Checked by says what catches the Don't in a caller's code.

RuleLevelDoDon'tChecked by
DD-1mustSay what is happening, then how sure we are, in plain sentences: a title such as "Signal fault at Danshøj" above a sentence such as "Trains between Flintholm and Ny Ellebjerg run slower than planned. We don't know yet when the fault will be fixed."Write "Error!" or "Something went wrong": content design has no exclamation marks, and the title should say what failedreview
DD-2mustPick the color the words say: success for something that went well, warning for something to take care with, danger for something that failedLet the colour or the icon be the only sign: every message says its meaning in words tooreview
DD-3shouldUse SeverityLabel or a DisruptionCard for a disruption on a line, and NormalService for a line running normallyUse an Alert for each disruption: a disruption has its own words, icons and colours, and a list of tinted boxes is not calmreview
DD-4shouldUse DataStatePanel or EmptyState when a data view is loading, empty or could not loadPut an Alert in place of the data view's content: it sits beside content, it doesn't stand in for itreview
DD-5mustGive one action at most, a small outline neutral Button or a LinkButtonAdd a brand action: a screen has one brand action at most, and the message is not itreview
DD-6mustRemove the alert in onClose and move focus to the element before itLeave focus on a close button that is gone: it drops to the top of the pagereview
DD-7mustAdd a message that must be heard as it appears inside a live region already on the page, or pass role="alert" for a failure that stops the taskPass role="alert" on every danger message, or add a live region of your own around an Alert shown on load: it interrupts, or adds noisereview
DD-8mustShow a message that comes and goes on its own, such as "Link copied", as a ToastMake an Alert disappear on a timer: an inline message stays until the person or the data says otherwisereview