Skip to content

Kbd, KeyCap and Keys ​

A shortcut as the platform prints it: ⌘K on macOS, Ctrl+K elsewhere. Kbd prints it as one chip, Keys as one cap per key, and KeyCap is a single cap.

tsx
import { Kbd, KeyCap, Keys } from '@adecore/ui';
tsx
import { Kbd, KeyCap, Keys, shortcut } from '@adecore/ui';

const PALETTE = shortcut('Mod+Shift+P');
const PAN = shortcut('Mod');

export default function KbdDemo() {
    return (
        <div className="flex flex-col items-center gap-4 text-xs text-text-muted">
            <p>
                Open the palette with <Kbd shortcut={PALETTE} variant="inline" />, close it with <Kbd variant="inline">Esc</Kbd>.
            </p>
            <div className="flex items-center gap-6">
                <Keys shortcut={PALETTE} />
                <Keys shortcut={PAN} then="drag" />
                <KeyCap>↑</KeyCap>
            </div>
        </div>
    );
}

Kbd ​

Kbd takes a Shortcut and prints it for the platform. Without one it prints its children, for a key such as Esc or ↑.

variant="menu" (the default) draws no chip of its own; a menu row styles it as the hint at its end. Elsewhere, such as in a sentence, a tooltip or a footer, use variant="inline" for a chip.

Keys and KeyCap ​

Keys prints a shortcut key by key, as a settings page lists them. then="drag" adds a cap for a pointer gesture after the keys. KeyCap is one cap.

size="sm" caps fit inside a small field, such as the hint at the end of a search field.

Props ​

ComponentPropTypeDefault
KbdshortcutShortcutPrinted for this platform.
childrenReactNodePrinted as it is when there is no shortcut.
variant'menu' | 'inline''menu'
KeysshortcutShortcutRequired.
thenstringThe gesture the keys go with, as one more cap.
size'md' | 'sm''md'
KeyCapchildrenReactNodeRequired.
size'md' | 'sm''md'

All three take className and ref. KbdProps, KeysProps and KeyCapProps are exported types.

Licenses and third-party notices are listed in each package.