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 is a key string, resolved like the value of Kbd, or a Kbd props object with value. Known aliases resolve to symbol notation and spoken names. Use an object to set aria-label, symbol, or translations for one key. The group’s size and variant apply to every key.

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

Separator#

separator defaults to "+" and accepts a string or number for inline notation. For custom JSX, pass a component that receives the index of the key it follows; each position mounts its own instance. It is unrelated to the layout Separator.

<KbdGroup items={['Ctrl', 'Shift', 'K']} separator="/" />
<KbdGroup items={['Ctrl', 'K']} separator={() => <span class="text-muted-foreground">then</span>} />

Examples#

Label save and format shortcuts#

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>
  )
}

Show a chord with a custom divider#

Pass a separator component when the notation should not use +.

import { KbdGroup } from 'moraine'

export function CustomSeparator() {
  return (
    <KbdGroup
      items={['Ctrl', 'Shift', 'K']}
      separator={() => <span class="text-muted-foreground">/</span>}
    />
  )
}

API Reference#

Props#

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

Prop