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.
<Kbd>⌘K</Kbd><Kbd>ESC</Kbd>Installation
import { Kbd } from "@catalog-dashboard/components";Anatomy
- 1 · Chip. An 8% tint of the text color with 5px corners. No ring, no border and no shadow.
- 2 · Key. The interface's own font, medium weight, in the secondary text color. Monospace is
InlineCode's.
| Size | Height | Least width | Text | Side padding |
|---|---|---|---|---|
md | 20px | 20px | label-4, 11px | 6px |
sm | 16px | 16px | label-5, 10px | 4px |
Sizes
Two: md, the default, and sm, for a small menu's rows. What each measures is in the table under Anatomy.
<Kbd>⌘K</Kbd><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.
<Kbd>⌘</Kbd><Kbd>⇧</Kbd><Kbd>↵</Kbd><Kbd>ESC</Kbd><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.
<Kbd>⌘K</Kbd><Kbd>↑↓</Kbd><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.
<KbdGroup> <Kbd>⌘</Kbd> <Kbd>⇧</Kbd> <Kbd>P</Kbd></KbdGroup> <KbdGroup> <Kbd>G</Kbd> then <Kbd>A</Kbd></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.
<DropdownMenu> <DropdownMenuTrigger render={<Button size="sm">Open a menu</Button>} /> <DropdownMenuContent> <DropdownMenuGroup> <DropdownMenuItem iconStart={Copy} shortcut="⌘C">Copy ID</DropdownMenuItem> <DropdownMenuItem shortcut="⌘D">Duplicate</DropdownMenuItem> </DropdownMenuGroup> </DropdownMenuContent></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.
<Tooltip> <TooltipTrigger render={<Button size="sm" iconStart={MagnifyingGlass} aria-label="Search" />} /> <TooltipContent> <span className="flex items-center gap-1.5"> Search <Kbd>⌘K</Kbd> </span> </TooltipContent></Tooltip>In the dashboard
Where the dashboard shows a key today. All are this one component: the dashboard imports it directly.
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
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
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…).
| Prop | Type | Default | Description |
|---|---|---|---|
size | "md" | "sm" | "md" | The chip's height and text size. sm is for a small menu's rows. |
children | ReactNode | — | 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.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | 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?
OpenEvery 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.
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?
OpenThe 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.
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⌘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.
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?
OpenThe 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.
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?
OpenThe 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.
Not looked up on their pages.
Where does a key go, outside a menu row?
OpenOnly 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.
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 advise | Who |
|---|---|
| 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 expose | Ours | Why |
|---|---|---|
| A group of keys (shadcn's KbdGroup) | Added | KbdGroup, new and not used by a screen yet. |
| Two sizes (Polaris, Primer) | Already there | md and sm. |
| A key at the end of a menu row (Primer, as the row's trailing visual) | Already there | DropdownMenuItem's shortcut. |
| A key inside a tooltip (shadcn; Atlassian and Primer as a prop of the tooltip) | Ask | A 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) | Ask | The 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) | Ask | Our Kbd changes color only inside a tooltip. |