Kbd

Alignment target:@astryxdesign/core v0.7.1 · Kbd

<Kbd
  keys="mod+k"
/>

Props #

NameTypeDefaultDescription
keysstring-Required. The keyboard shortcut to present, with the keys separated by +, such as "mod+k" or "shift+plus". Each segment paints one key badge; whitespace around a segment is ignored, and an unrecognized segment is uppercased. Modifiers paint Apple's symbol on Apple platforms and text elsewhere and before hydration (see the table below). In development, a keys that is not a string throws an error naming the prop; Kbd does not read slot content.

Key names #

Written asPainted asSpoken as
mod⌘ / CtrlCommand on Apple platforms, Control elsewhere
ctrl⌃ / CtrlControl
alt⌥ / AltAlt
shift⇧ / ShiftShift
meta⌘ / WinMETA
enter / return↵Enter
backspace⌫Backspace
tab⇥Tab
escape / escEscEscape
up↑Up arrow
down↓Down arrow
left←Left arrow
right→Right arrow
plus+Plus

A segment that is not in this table is painted uppercased as written and spoken as that same text, so f1 paints as F1.

Accessibility #

The root element carries role="img" and an aria-label assembled from the spoken key names, so keys="mod+k" is announced as "Control + K". The badges themselves are aria-hidden="true", because the glyphs they paint mean nothing to assistive technology. role and aria-label are computed by the component, and a consumer value for either is ignored; every other aria-* attribute passes through.

Native attributes #

The root element is a <span>.

The following go to the root element:

  • HTML attributes.
  • aria-* attributes, except role and aria-label (see the previous section).
  • data-* attributes.
  • class.
  • style.