On this page

InstallationAnatomySizesSymbols and wordsA shortcut in one chipOne chip per keyIn a menu rowIn a tooltipIn the dashboardAccessibilityAPI ReferenceKbdKbdGroupRulesWritten downOpen questionsWhat others adviseWhat others expose

Kbd

A key or a shortcut, drawn as a small chip: the search's ⌘K, a menu row's shortcut, the hints under the command palette.

⌘KESC
1<Kbd>⌘K</Kbd>2<Kbd>ESC</Kbd>

Installation

text
import { Kbd } from "@dome-systems/ds-dashboard/components";

Anatomy

⌘K12
  1. 1 — Chip. An 8% tint of the text color with 5px corners. No ring, no border and no shadow.
  2. 2 — Key. The interface's own font, medium weight, in the secondary text color. Monospace is InlineCode's.
SizeHeightLeast widthTextSide padding
md20px20pxlabel-4, 11px6px
sm16px16pxlabel-5, 10px4px

Sizes

Two: md, the default, and sm, for a small menu's rows. What each measures is in the table under Anatomy.

⌘K⌘K
1<Kbd>⌘K</Kbd>2<Kbd size="sm">⌘K</Kbd>

Symbols and words

The Kbd draws the text it is given: a symbol, a word, a letter. One character makes a square: the chip is never narrower than it is tall. How each key should be written is an open question.

⌘⇧↵ESCK
1<Kbd>⌘</Kbd>2<Kbd>⇧</Kbd>3<Kbd>↵</Kbd>4<Kbd>ESC</Kbd>5<Kbd>K</Kbd>

A shortcut in one chip

How the dashboard writes every shortcut today: the keys together in one Kbd, with no sign between them.

⌘K↑↓←→
1<Kbd>⌘K</Kbd>2<Kbd>↑↓</Kbd>3<Kbd>←→</Kbd>

One chip per key

New. KbdGroup holds several keys of one shortcut, each in its own Kbd, 4px apart. A word between keys ("then") is plain text inside the group, at the size of the text around it. No screen uses it.

⌘⇧PGthenA
1<KbdGroup>2  <Kbd>⌘</Kbd>3  <Kbd>⇧</Kbd>4  <Kbd>P</Kbd>5</KbdGroup>6
7<KbdGroup>8  <Kbd>G</Kbd>9  then10  <Kbd>A</Kbd>11</KbdGroup>

In a menu row

A menu row takes its key as shortcut and draws the Kbd itself, at the row's end and at the menu's size.

1<DropdownMenu>2  <DropdownMenuTrigger render={<Button size="sm">Open a menu</Button>} />3  <DropdownMenuContent>4    <DropdownMenuGroup>5      <DropdownMenuItem iconStart={Copy} shortcut="⌘C">Copy ID</DropdownMenuItem>6      <DropdownMenuItem shortcut="⌘D">Duplicate</DropdownMenuItem>7    </DropdownMenuGroup>8  </DropdownMenuContent>9</DropdownMenu>

In a tooltip

Inside a tooltip the Kbd changes its colors by itself: its text takes the page's background color, on a tint of the same. In the light theme that is light text on the dark pill. In the dark theme it does not hold up: the page's background is nearly the pill's own color, so by the tokens the key cannot be read. No screen puts a key in a tooltip today.

1<Tooltip>2  <TooltipTrigger render={<Button size="sm" iconStart={MagnifyingGlass} aria-label="Search" />} />3  <TooltipContent>4    <span className="flex items-center gap-1.5">5      Search <Kbd>⌘K</Kbd>6    </span>7  </TooltipContent>8</Tooltip>

In the dashboard

Where the dashboard shows a key today. All are this one component: the dashboard's components/ui/kbd.tsx re-exports it.

Search⌘K

The sidebar's Search

The row ends in ⌘K. The chip is hidden from a screen reader and the row carries aria-keyshortcuts. Folded to icons, the dashboard hides the key.

components/layout/universal-search.tsx

↑↓ Navigate←→ Expand↵ Open

The command palette

ESC beside the input, and a footer of hints in secondary text: each key, then what it does.

components/layout/universal-search.tsx

Copy ID ⌘C

A menu row's shortcut

DropdownMenuItem's shortcut prop: see the live menu above.

ds/components/dropdown-menu.tsx

Accessibility

A Kbd is the HTML <kbd> element, so a screen reader reads its text where it stands. It is read, never pressed: it takes no pointer, its text cannot be selected, and the Tab key passes over it.

What a screen reader says for a symbol like ⌘ was not tested. The dashboard handles it two ways today, described in the open question on spoken keys.

Its text is the secondary text color on an 8% tint of the text color, which clears 4.5 to 1 on a card in both themes.

API Reference

Kbd

Besides these, the props of a <kbd> (aria-hidden…).

PropTypeDefaultDescription
size"md" | "sm""md"The chip's height and text size. sm is for a small menu's rows.
childrenReactNode—The key or the shortcut, drawn as given.

KbdGroup

New, not used by a screen yet. Imported beside Kbd. No props of its own: a <kbd> around several Kbd, which is how HTML writes a shortcut made of keys.

PropTypeDefaultDescription
childrenReactNode—Several Kbd, and any word between them as plain text.

Rules

Written down

The look is the component's own

No call site adds to it, so a key is the same chip in the sidebar, in the command palette and in a menu.

From ds/README.md (Kbd) and ds/components/kbd.tsx.

A menu row's shortcut ends the row

DropdownMenuItem's shortcut draws the Kbd: as far from the row's end as from its top and bottom, 4px, and 4px after a badge.

From ds/components/dropdown-menu.tsx and ds/README.md (Dropdown menu).

sm is for a small menu's rows

The menu row picks the size from its menu. Nothing written says where else a small Kbd goes.

From ds/components/kbd.tsx and ds/components/dropdown-menu.tsx.

Open questions

One chip for the shortcut, or one chip per key?

Open
Ours

Every shortcut in the dashboard is one chip today (⌘K, ↑↓), and a menu row's shortcut is one string in one Kbd. KbdGroup, which is new, draws the other form. Nothing written chooses.

Other systems

shadcn shows both: a chip per key, and whole shortcuts ("Ctrl + B") in one chip. Primer draws a combination as one chip with its keys apart inside, splits only a sequence into chips, and can write a plus sign between keys.

How is each key written?

Open
Ours

The dashboard writes ⌘K, ESC, ↑↓, ←→ and ↵: symbols for modifiers, arrows and Enter, a word in capitals for Escape. Nothing written says symbol or word, capitals or not, or the order of modifiers.

Other systems

shadcn draws the text it is given. Polaris lowercases a word and capitalizes a single letter. Primer takes one spelling and draws symbols or full words from it.

What does someone on Windows see?

Open
Ours

⌘K on every machine. The search opens with ⌘K or Ctrl K, so on Windows and Linux the chip names a key the keyboard does not have.

Other systems

Primer writes a shortcut once ("Mod+K") and shows ⌘ on a Mac and Ctrl elsewhere.

Should a key be said in words to a screen reader?

Open
Ours

The product does two things. The sidebar's Search hides its chip and gives the row aria-keyshortcuts (Meta+K Control+K). The command palette's chips (ESC, ↑↓, ←→, ↵) are not hidden and are read as they are written. Nothing written chooses.

Other systems

Primer's source puts a hidden key name beside each symbol it draws. Atlassian hides a tooltip's shortcut from assistive technology and says to always give another way.

A key in running text: a Kbd, or InlineCode?

Open
Ours

The README's Inline code row lists "a key" among the literals it is for, without saying which kind of key; its Kbd row says a Kbd is a key or a shortcut. No screen writes a keyboard key inside a sentence today.

Other systems

Not looked up on their pages.

Where does a key go, outside a menu row?

Open
Ours

Only the menu row is written down. Today the Search row ends in its key, and the palette's hints put the key before the word. No button and no tooltip shows a key.

Other systems

Primer and Atlassian give their tooltip a prop for the shortcut. shadcn shows a key inside a tooltip, a button and an input.

What others advise

None of this is decided for us. It is what Atlassian, Polaris and Primer tell their own teams, listed so you can pick.

Others adviseWho
Don't show a hint for a shortcut that is not available where the person is.Primer
The words for the action sit beside its key.Polaris, Primer
The key sits beside the control it speeds up.Primer
A shortcut shown in a tooltip does not reach assistive technology: always give another way to learn it.Atlassian

What others expose

What shadcn, Primer, Polaris and Atlassian offer for keys, and where ours stands on each.

They exposeOursWhy
A group of keys (shadcn's KbdGroup)AddedKbdGroup, new and not used by a screen yet.
Two sizes (Polaris, Primer)Already theremd and sm.
A key at the end of a menu row (Primer, as the row's trailing visual)Already thereDropdownMenuItem's shortcut.
A key inside a tooltip (shadcn; Atlassian and Primer as a prop of the tooltip)AskA Kbd in TooltipContent recolors itself, but reads in the light theme only. No tooltip prop for it.
A key inside an input (shadcn's input group)AskThe Input's end takes a word, not a Kbd.
A key on a button (Primer, with colors for a solid button; shadcn on an outline one)AskOur Kbd changes color only inside a tooltip.