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
Section titled “Import”import { Kbd } from 'nacre'import { Kbd } from 'nacre'
export function KbdUsage() { return <Kbd>⌘K</Kbd>}Examples
Section titled “Examples”Key combinations
Section titled “Key combinations”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 text
Section titled “In text”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> )}No fill
Section titled “No fill”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> )}Accessibility
Section titled “Accessibility”- 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 / Don’t
Section titled “Do / Don’t”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