Kbd
Keycap badges that physically depress with a snappy spring on real key presses and light up in sequence inside KbdGroup combos.
Customize
Installation
npx shadcn@latest add @kinetic/kbdUsage
Render Kbd directly with a key glyph or explicit keys aliases. All mounted Kbd instances share one ref-counted window listener and clean up automatically when unmounted.
import { Kbd } from "@/components/kinetic/ui/kbd";
interface ShortcutHintProps {
readonly label: string;
}
export function ShortcutHint({ label }: ShortcutHintProps) {
return (
<span className="inline-flex items-center gap-2 text-sm text-muted-foreground">
<span>{label}</span>
<Kbd keys="k">K</Kbd>
</span>
);
}Key combinations (KbdGroup)
Group shortcut keys inside KbdGroup to cascade highlight feedback sequentially when all keys in the combo are held together. Key listeners observe without calling preventDefault().
import { Kbd, KbdGroup } from "@/components/kinetic/ui/kbd";
interface CommandBadgeProps {
readonly onMatched?: () => void;
}
export function CommandBadge({ onMatched }: CommandBadgeProps) {
return (
<KbdGroup onMatch={onMatched}>
<Kbd keys="meta">⌘</Kbd>
<Kbd keys="k">K</Kbd>
</KbdGroup>
);
}Key alias normalization & reduced motion
normalizeKeyToken normalizes aliases such as ⌘ / Cmd / Meta, Ctrl, Alt / Option / ⌥, Shift, Enter, Esc, and case-insensitive single keys or KeyboardEvent.code tokens (KeyK, Digit1). Under reduced motion, keycaps switch surface highlight colors cleanly with zero translation.
API Reference
Kbd
Subscribes via shared ref-counted store and sinks downward with SPRING.snappy when matching keys are held.
| Prop | Type | Default | Description |
|---|---|---|---|
keys | string | readonly string[] | - | Explicit key aliases or KeyboardEvent.key/code tokens (inferred from plain children if omitted). |
listen / pressed / speed | boolean / boolean / number | true / undefined / 1 | Enable global keyboard tracking, override pressed state manually, and scale spring speed. |
KbdGroup
Highlights child Kbd badges sequentially when every key in the shortcut is held simultaneously.
| Prop | Type | Default | Description |
|---|---|---|---|
keys / staggerMs / onMatch | readonly string[] / number / () => void | child keys / 55 / undefined | Override combo keys, configure cascade delay, and handle combo match events. |