Skip to content
Nacre
Color palette
中文

Kbd

stableKbdOpen in playground
Kbd
Runs the real component in your browser.

Shows a shortcut in tooltips, help and empty states: a gray keycap 20 tall and at least 20 wide. Icon buttons and menu items use their own shortcut; don’t assemble one by hand.

Status: stable · Components: Kbd

import { Kbd } from 'nacre'
import { Kbd } from 'nacre'
export function KbdUsage() {
return <Kbd>⌘K</Kbd>
}

One combination goes in one keycap, with modifiers first in macOS order ⌃⌥⇧⌘; a single key is written by name (Esc, Return).

import { View } from 'nsh'
import { Kbd } from 'nacre'
export function KbdKeys() {
return (
<View class="flex-row items-center gap-2">
<Kbd>⌘K</Kbd>
<Kbd>⇧⌘E</Kbd>
<Kbd>⌃⌘S</Kbd>
<Kbd>Esc</Kbd>
<Kbd>Return</Kbd>
</View>
)
}

In help and empty-state sentences, the keycap sits on the same line as the text, vertically centered.

import { Text, View } from 'nsh'
import { Kbd, TEXT_SIZE } from 'nacre'
export function KbdInline() {
return (
<View class="gap-2">
<View class="flex-row items-center gap-1.5">
<Text class={`${TEXT_SIZE.small} text-muted-foreground`}>Press</Text>
<Kbd>⌘K</Kbd>
<Text class={`${TEXT_SIZE.small} text-muted-foreground`}>to search chats</Text>
</View>
<View class="flex-row items-center gap-1.5">
<Text class={`${TEXT_SIZE.small} text-muted-foreground`}>Press</Text>
<Kbd>Esc</Kbd>
<Text class={`${TEXT_SIZE.small} text-muted-foreground`}>to close the preview</Text>
</View>
</View>
)
}

Use bare inside a control that already has a translucent fill (a search entry), so the opaque gray fill isn’t the brightest spot.

import { Text, View } from 'nsh'
import { Icon, Kbd, TEXT_SIZE } from 'nacre'
export function KbdBare() {
return (
<View class="w-[240px] max-w-full h-7 flex-row items-center gap-1.5 px-2 rounded-md bg-fill-subtle">
<Icon name="search" size={14} color="muted-foreground" />
<Text class={`flex-1 ${TEXT_SIZE.small} text-muted-foreground`}>Search chats</Text>
<Kbd bare>⌘K</Kbd>
</View>
)
}
  • A keycap is plain text that screen readers read character by character; the sentence should spell out the action (“Press ⌘K to search chats”).

Do

  • Use macOS symbols (⌘ ⇧ ⌥ ⌃)
  • One keycap per combination
  • Use the shortcut prop on icon buttons and menu items

Don’t

  • Put a shortcut in a button’s text
  • Split each modifier into its own keycap
Prop Type Default Description
children * string —
testID string —
bare boolean —

* required