Skip to main content

Kbd

Keycap badges that physically depress with a snappy spring on real key presses and light up in sequence inside KbdGroup combos.

Press ⌘K⌘K
Quick save:⇧PClose:Esc
Type directly on your keyboard to watch matching keycaps compress.

Customize

Group stagger (ms)55
Speed1

Installation

npx shadcn@latest add @kinetic/kbd

Usage

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.

PropTypeDefaultDescription
keysstring | readonly string[]-Explicit key aliases or KeyboardEvent.key/code tokens (inferred from plain children if omitted).
listen / pressed / speedboolean / boolean / numbertrue / undefined / 1Enable 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.

PropTypeDefaultDescription
keys / staggerMs / onMatchreadonly string[] / number / () => voidchild keys / 55 / undefinedOverride combo keys, configure cascade delay, and handle combo match events.

Notes

Use normalizeKeyToken aliases like Meta/Cmd, Ctrl, Alt/Option, Shift, Enter, Esc, or single characters without case sensitivity.