Rost

← All components

component

Kbd

A key on the keyboard, written in the text. A small grey cap with the key's name in mono.

In code Contract: review Guidance: proposed Contract on GitHub Figma 742:25 As markdown
Esc
Default

Install

npx github:Runceanu/rost add kbd

It lands in src/rost/kbd/, with what it needs and its contract. Install has the rest.

When to use

  • Shortcuts

    Telling someone which keys do something: Press ⌘ + K to search.

When not to use

Behaviour

A cap per key. It doesn't press: it's text.

Accessibility

  • Element

    <kbd>, which screen readers know as keyboard input.

  • Name

    The key's name. Write symbols out in an aria-label when they'd be read oddly (⌘ is "Command").

  • Colour

    The key's name is 11:1 on its cap in dark.

Content

The key as it's printed on the keyboard: Esc, Enter, Tab, ⌘.

Props

PropTypeValuesDefault
children slot

Values

Straight from the contract. Each value sits next to its token, because six tokens here all come out as #3a3a3a and the colour alone can't tell you which one is right.

Never changes

root

  • min-width 20px spacing/size/xsmall
  • height 20px spacing/size/xsmall
  • padding-left 6px spacing/gap/xsmall
  • padding-right 6px spacing/gap/xsmall
  • border-radius 4px spacing/radius/xsmall
  • background #171717 kbd/background
  • outline-width 1px spacing/outline/small
  • outline-offset calc(-1 * var(--spacing-outline-small)) on purpose: Composed from a token: the edge sits inside.
  • outline-color #3a3a3a kbd/edge
  • font-family 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace no token yet
  • font-weight 500 typography/label/font-weight/medium
  • font-size 12px typography/label/font-size
  • line-height 14px typography/label/line-height
  • color #d3d9d5 kbd/label

displayinline-flex · align-itemscenter · justify-contentcenter · vertical-alignmiddle · outline-stylesolid