Components

Kbd

A key the user presses, drawn as a small keycap. Use it for shortcuts in menus, tooltips and search fields.

Usage

import { Kbd, KbdGroup, SpecialKeys } from 'nyctoui/kbd'

<KbdGroup>
  <Kbd>{SpecialKeys.Cmd}</Kbd>
  <Kbd>K</Kbd>
</KbdGroup>

One Kbd per key. Wrap keys pressed together in a KbdGroup, which renders the nested <kbd> HTML uses for a key combination.

SpecialKeys holds the glyphs for keys drawn as symbols, such as SpecialKeys.Cmd for ⌘. Screen readers have no name for these symbols, so a Kbd holding one gets its name as a title, like “Command”. Pass your own title to change it.

Good for

  • Shortcuts beside items in an app’s menus.
  • A “⌘ K” hint inside a search field in a header.
  • A keyboard shortcuts help sheet in a productivity app.
  • Instructions in docs, such as “Press Enter to send”.

Anatomy

<KbdGroup>
  <Kbd />
</KbdGroup>

Examples

Keys

A single character gets a square cap; words like Esc widen it.

Special keys

Every glyph in SpecialKeys, by name. Keys that read better as words, such as Esc, Home or Page Up, are left out; write those as text.

Group

The group spaces its keys and takes plain text between them, for a sequence pressed one key after another.

In text

Keys sit on the baseline, so they read inline in a sentence.

In an input

Put the key in an InputAddon after the field to show the shortcut that focuses it, as a search field often does. The hint only describes the shortcut; bind the key yourself.

In a button

The button’s gap spaces the key from the label. Use it on ghost and secondary buttons; the cap’s muted colors are meant for light fills.

In a dropdown

Put keys in a DropdownShortcut to align them to the end of the item.

Best practices

Do
  • Show shortcuts right next to the action they trigger: in a menu item, a tooltip or a sentence.
  • Show the keys for the platform people are on, ⌘ on a Mac and Ctrl elsewhere.
  • Group the keys of one shortcut in a KbdGroup, so they read as one combination.
Don’t
  • Make a shortcut the only way to find an action. It speeds up a visible control; it doesn’t replace one.
  • Expect Kbd to listen for the keys. It only draws them; handle the shortcut in your own code.

API reference

Kbd

One key. Renders a <kbd>.

PropTypeDefault
title
Spoken and hover name. Defaults to the key’s name for a SpecialKeys glyph.
string—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

KbdGroup

Keys pressed together or in sequence. Renders a <kbd>.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

SpecialKeys

Glyphs for keys drawn as symbols. A plain object of strings; SpecialKey is the union of its names.

PropTypeDefault
Cmd
Command
'⌘'—
Shift
Shift
'⇧'—
Option
Option, or Alt
'⌥'—
Ctrl
Control
'⌃'—
Enter
Enter, or Return
'↵'—
Backspace
Backspace, Delete on a Mac
'⌫'—
Delete
Forward delete
'⌦'—
Tab
Tab
'⇥'—
CapsLock
Caps Lock
'⇪'—
Up
Up arrow
'↑'—
Down
Down arrow
'↓'—
Left
Left arrow
'←'—
Right
Right arrow
'→'—