Skip to the content

Kongens Nytorv

Metro M1, M2 and M3.

Esc

Props

NameTypeDefaultDescription
children*ReactNode—One key, as the keyboard prints it or the platform names it: "Esc", "Enter", "+", "−", "↑". Required: a key with no name says nothing. A combination is one Kbd per key (CR-5).
children (required)ReactNode, default —
One key, as the keyboard prints it or the platform names it: "Esc", "Enter", "+", "−", "↑". Required: a key with no name says nothing. A combination is one Kbd per key (CR-5).

Use it

import { Kbd } from '@mylder/perron'

Ask your agent

search_docs({ query: "Kbd" })

Keyboard and ARIA

No keys: Kbd is not focusable and does nothing when pressed (CR-2). It names a key; the key's action is the screen's, and the control the key works is the caller's to mark with aria-keyshortcuts, as Accessibility gives the keys.

KeyDoesFrom
NoneKbd is not focusable or operablePerron
ElementRoleAccessible name fromStates announced
rootnone: a <kbd>, which has no ARIA role and is read as its textIts text, the caller's childrennone

A screen reader reads the key's text in the sentence around it, as written: "Esc", "plus", "minus", "up arrow" for "Esc", "+", "−", "↑". Kbd adds no aria-label and no owned word for the key: the caller's text is already the key's name, and a <kbd> without a role can't carry aria-label reliably.

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 box only says "this is a key"; the key itself is the text inside it, which a screen reader reads in place, and children is required.
  • Every landmark and named region has an accessible name: none here; the key is inline text.
  • Every default label can be overridden: no owned strings, so no *Label props.
  • Every shape the type accepts renders, in every variant: children renders as a string, an element and a list alike, on one line inside the box; Kbd.test.tsx checks all three, each inside the one <kbd> with pn-Kbd first.
  • A hidden copy kept for animation is aria-hidden, and a collapsed region is inert: none here; the key has no motion.
  • Native semantics first: the native <kbd>, with no ARIA.
  • Focus moves in reading order and returns on close: never focused; it has no tab stop.
  • Every target is at least size.target-min square: no target; Kbd is never pressed. A pressable key hint is the caller's button with the Kbd inside it, which meets the minimum itself.
  • Loops stop when the system asks for less motion: none here; the key has no motion.

Owned strings

No owned strings: the key's name is the caller's children, and Kbd announces nothing else.

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-1shouldName keys in help text, one Kbd per key, as content design writes it: "Keys: + and − zoom, arrows pan, Esc closes panels."Write a key as a quoted word, "press 'Esc'", where a Kbd says it is a keyreview
DD-2mustWrite the key as the keyboard prints it or the platform names it, in its own case: "Esc", "Enter", "−", "↑"Write it in capitals ("ESC"), as an emoji, or as an icon; the key's text is what a screen reader hearsreview
DD-3shouldName the left and right arrows in words, or all four as "arrows", as content design writes it: "arrows pan"Put "←" or "→" in a Kbd; the font Perron ships has no glyph for them, so they fall back to the system's monospace and look unlike the other keysreview
DD-4shouldGive a combination one Kbd per key, with "+" between them in the text: <Kbd>Ctrl</Kbd> + <Kbd>K</Kbd>Put a whole combination or a sentence in one Kbd; the box is sized for one keyreview
DD-5mustMark the control a key works with aria-keyshortcuts, and keep the action reachable by pressing the control tooMake the Kbd the only way to learn or do the action, or add onClick or tabIndex to itreview
DD-6shouldShow key hints where people have a keyboard, such as the help on a desktop screenShow keys on a phone's screen, which has no keyboard to press them onreview