Kbd

View registry JSON

Platform-aware keyboard keycaps with live press feedback and optional shortcut callbacks.

Install with the shadcn CLI

npx shadcn@4.21.5 add @cavemio/kbd
First install? Configure @cavemio once

Run npx shadcn@4.21.5 init if shadcn is not set up, then merge this entry into the registries field in your existing components.json. Keep your other settings and registries.

components.json
{
  "registries": {
    "@cavemio": "https://registry.cavemio.dev/r/cavemio-{name}.json"
  }
}

Overview

Platform-aware keyboard keycaps with live press feedback and optional shortcut callbacks.

Hold keys to see live feedback. Reduced motion keeps color and shadow feedback without movement; demo shortcuts stay local.

import { Kbd } from "@/components/kbd";

<Kbd hotkey="k" onTrigger={() => setOpen(true)} stopPropagation aria-label="Open commands" />

Props

PropTypeDescription
keysstring[] | stringOptional. Individual keys as an array or plus-separated string, e.g. mod+shift+p. Display only; hotkey controls callback binding.
livebooleanOptional, defaults to false. Track held keys with 1px press feedback. Does not claim keyboard events; disabled suppresses tracking.
size"sm" | "md"Optional, defaults to md. Individual keycap size for keys or live hotkey feedback.
hotkeystringOptional. Key combined with Cmd or Ctrl, e.g. "k". Empty/omitted disables the shortcut.
labelReact.ReactNodeOptional. Action label displayed beside the keycap in a full-size surface.
onTrigger( event: KeyboardEvent | React.MouseEvent<HTMLButtonElement>, ) => voidOptional. Called once by a click, Enter/Space, or the matching global shortcut.
stopPropagationbooleanOptional. Stop clicks and matching shortcuts before they reach ancestor handlers.
refReact.Ref<HTMLButtonElement>Optional. Button ref, available when onTrigger is supplied.