Skip to main content

KbdGroup

Display a multi-key shortcut with shared styling.

Quick save:Ctrl+⇧+S
Props
Slots

Anatomy#

KbdGroup [component; slot=root; <kbd>]
└── item [slot]

Separator content is inline and is not a theme slot.

Usage#

Use KbdGroup to display keys pressed together, such as Ctrl + K. It renders notation only; the application owns the shortcut listener. For a single keycap, use Kbd.

import { KbdGroup } from 'moraine'

export function Example() {
  return <KbdGroup items={['Ctrl', 'K']} />
}

Key labels#

Each item in items is either a key string (resolved like the value of Kbd) or an object { value, ariaLabel?, symbol? }.

Known aliases resolve to symbol notation and spoken names. The group’s size and variant apply to every key.

<KbdGroup items={['meta', 's']} />
<KbdGroup items={[{ value: 'meta', ariaLabel: 'Command' }, 'K']} />

Separator#

  • String: separator defaults to "+" and renders strings as plain text rather than an icon name.
  • Component: pass a component receiving { index } (the index of the preceding key) to render custom JSX such as an icon; each position mounts its own instance.

separator is inline notation and is unrelated to the layout Separator.

<KbdGroup items={['Ctrl', 'Shift', 'K']} separator="/" />
<KbdGroup items={['Ctrl', 'K']} separator={() => <Icon name="i-lucide:plus" />} />

Examples#

Basic#

Place the group beside the command it describes. Alias keys resolve to platform symbols by default.

import { KbdGroup } from 'moraine'

export function KbdGroupUsage() {
  return (
    <div class="flex flex-col gap-3">
      <div class="flex gap-2 items-center">
        <span class="text-sm text-muted-foreground">Save document:</span>
        <KbdGroup items={['meta', 's']} />
      </div>
      <div class="flex gap-2 items-center">
        <span class="text-sm text-muted-foreground">Format document:</span>
        <KbdGroup items={['shift', 'alt', 'f']} />
      </div>
    </div>
  )
}

Custom separator#

Pass a separator component when the separator is markup, such as an icon, rather than text.

import { Icon, KbdGroup } from 'moraine'

export function CustomSeparator() {
  return (
    <div class="flex gap-2 items-center">
      <span class="text-sm text-muted-foreground">Open command palette:</span>
      <KbdGroup
        items={['ctrl', 'shift', 'P']}
        separator={() => <Icon name="i-lucide:plus" class="text-muted-foreground" />}
      />
    </div>
  )
}

API Reference#

Props#

Props for the KbdGroup component. Renders a <kbd> element by default.

Prop