Components

Kbd

Keyboard keys for React styled as real keycaps, with a pressed state that sinks and brightens — plus an animated shortcut block whose keys sink as you press the combo, knows ⌘ from Ctrl without hydration mismatches, and ships a useShortcut hook.

  • shadcn API
  • Server Component friendly
  • Mac / Windows aware
  • No hydration mismatch
CommandJ

Press the shortcut — each key lights up as you hold it.

Installation

$ npx shadcn@latest add https://duskui.com/r/kbd.json

Adds components/ui/kbd.tsx with shadcn's Kbd and KbdGroup, plus size and pressed. CSS only.

Usage

search-hint.tsx
import { Kbd, KbdGroup } from "@/components/ui/kbd"

export function SearchHint() {
  return (
    <p className="text-sm text-muted-foreground">
      Press{" "}
      <KbdGroup>
        <Kbd>⌘</Kbd>
        <Kbd>K</Kbd>
      </KbdGroup>{" "}
      to search
    </p>
  )
}

Examples

Keycaps

Three sizes, icons sized automatically, and KbdGroup for combinations. Add pressed to show a key held down. Keys sit nicely inside running text too.

EscTabSpaceCommandShiftPEnter

Press CtrlB to toggle the sidebar, or / to jump to search.

In buttons

Hint the shortcut right on the control it triggers. Kbd flattens itself inside tooltips.

Blocks

Ready-made variations composed from the base component with Motion. Each installs on its own and pulls in its dependencies automatically.

Shortcut Kbd

Keycaps that listen. Each cap sinks while its key is held; when the full combination lands they dip once together and onTrigger runs. mod shows ⌘ on Apple devices and Ctrl elsewhere — the platform is read with useSyncExternalStore, so the server HTML and first client render always match. Letters match by physical key, so ⌥ and ⇧ can't change them. The file also exports useShortcut and usePlatform for your own UI.

CommandJ

Press the shortcut — each key lights up as you hold it.

$ npx shadcn@latest add https://duskui.com/r/shortcut-kbd.json
PropTypeDefaultDescription
keysstring[]—The combination, e.g. ["mod", "k"]. Modifiers: mod, ctrl, shift, alt (option), meta (cmd). Required.
onTrigger(event: KeyboardEvent) => void—Called when the full combination is pressed.
enabledbooleantrueListen for the shortcut.
preventDefaultbooleantrueStop the browser's own action for the combo.
enableInInputsboolean—Fire while typing in a field. Defaults to true for combos with mod / ctrl / meta / alt, false for plain keys.
size"sm" | "default" | "lg""default"Keycap size.
keyClassNamestring—Classes for each keycap.

Shortcut cheat sheet

Several ShortcutKbds make a live cheat sheet: every row lights up as you try it. Plain keys like J and / pause while you type in a field, so they never steal input.

  • Next itemJ
  • Previous itemK
  • Focus filter/
  • New noteOptionN
  • Show shortcuts?

Try the keys (they pause while you type in a field).

$ npx shadcn@latest add https://duskui.com/r/shortcut-kbd.json

API Reference

Kbd renders a <kbd>; KbdGroup renders a wrapping <kbd> so nested keys read as one shortcut.

PropTypeDefaultDescription
size"sm" | "default" | "lg""default"Kbd. Keycap size.
pressedbooleanfalseKbd. Shows the key held down: it sinks a pixel and brightens.

Accessibility

  • Keys use the semantic <kbd> element, and a group of keys is nested in another <kbd>, the HTML pattern for a key combination.
  • Give symbol keys a spoken name: pair ⌘ or an icon with <span className="sr-only">Command</span>. Shortcut Kbd does this for you (Command, Control, Shift, Option…).
  • Shortcut Kbd only listens; announce the result of a shortcut yourself, e.g. with a polite live region as in the demos.
  • Avoid single-key shortcuts for destructive actions; they are paused inside text fields by default, but can still be pressed by accident.
  • Under prefers-reduced-motion the trigger dip is a surface change only, without movement.