Skip to main content

Kbd

A keyboard key, or a shortcut of several, for menus, tooltips and help text. Screen readers say the symbols as words: ⌘ K is read "Command K".

import { Kbd } from 'patine-ui';
Loading…
<Box border radius="lg" padding="md" style={{ width: 320 }}>
  <Text weight="semibold" style={{ marginBottom: 8 }}>Keyboard shortcuts</Text>
  <VStack>
    {SHORTCUTS.map((s, i) => (
      <React.Fragment key={s.label}>
        {i > 0 ? <Separator /> : null}
        <HStack justify="space-between" style={{ paddingVertical: 10 }}>
          <Text>{s.label}</Text>
          <Kbd keys={s.keys} />
        </HStack>
      </React.Fragment>
    ))}
  </VStack>
</Box>

Try the props​

Props
size
separator
design
<Kbd keys={['⌘', 'K']} />

Example: a shortcuts sheet​

A text editor's help panel: the same shortcuts for Mac and for Windows and Linux, grouped by what they do. Switch the platform to see the keys change.

Loading…
<Box border radius="lg" padding="md" gap="md" style={{ width: '100%', maxWidth: 380 }}>
  <SegmentedControl items={[{ value: 'mac', label: 'Mac' }, { value: 'pc', label: 'Windows and Linux' }]} value={os} onValueChange={setOs} />
  {GROUPS.map((group) => (
    <VStack key={group.title}>
      <Text size="sm" weight="semibold" color="textSecondary">{group.title}</Text>
      {group.items.map((item, i) => (
        <VStack key={item.label}>
          {i ? <Separator /> : null}
          <HStack justify="space-between" align="center" style={{ paddingVertical: 8 }}>
            <Text>{item.label}</Text>
            <Kbd keys={item.keys.map((k) => KEYS[os][k] ?? k)} separator={os === 'pc' ? '+' : undefined} />
          </HStack>
        </VStack>
      ))}
    </VStack>
  ))}
</Box>

In a sentence​

Loading…
<HStack gap="xs" wrap>
  <Text>Press</Text>
  <Kbd keys={['Ctrl', 'C']} separator="+" size="sm" />
  <Text>to copy, or</Text>
  <Kbd size="sm">Esc</Kbd>
  <Text>to cancel.</Text>
</HStack>

Designs​

brand and web draw an outlined keycap with a heavier bottom edge, as GitHub and shadcn do. iOS and Material draw a flat tonal chip.

Accessibility​

The keys are one element named by the shortcut, with symbols as words: ⌘ Command, ⇧ Shift, ⌥ Option, ⌃ Control, ↵ Enter, ⌫ Delete, ⎋ Escape, ⇥ Tab and the arrows.

Props​

Also takes View props.

PropTypeDefaultDescription
childrenstring—One key.
keysstring[]—A shortcut, one key each. Wins over children.
separatorstringnoneBetween keys, e.g. '+'.
size'sm' | 'md''md'20 or 24 points tall.
textStyleStyleProp<TextStyle>—The key's text.
theme, designAs every component.