Kbd

Slant / Primitives

A keyboard key, for shortcuts in text and menus.

Demo

Usage

@tuttn/slant
import { Kbd, Text } from '@tuttn/slant'

<Text>Press <Kbd>⌘</Kbd> <Kbd>K</Kbd> to open the command bar.</Text>

// One key or a whole shortcut: the children are the text on the key.
<Kbd>⌘K</Kbd>
<Kbd>Esc</Kbd>

Props

PropTypeDefaultDescription
childrenReactNode—The key or shortcut as text: ⌘K, Esc, Ctrl.
…restHTMLAttributes—className, style and every other attribute go on the <kbd>, and a ref reaches it.

Accessibility

  • Renders a native <kbd>, so a screen reader reads the key as text, in line with the sentence around it.
  • Screen readers say symbols such as ⌘, ⌥ and ⇧ differently, or skip them. Where the shortcut matters, name the keys in words too.
  • Kbd only shows a key; it doesn't bind one. Handle the shortcut yourself, and announce it with aria-keyshortcuts on the control it triggers.

CommandBar draws its shortcut (⌘K by default) and each command's hint with Kbd.