Keyboard Shortcut

A keyboard shortcut display that reacts to each pressed key, triggers a callback when the full chord is held, and optionally plays key sounds.

Installation

npx shadcn@latest add @navui/keyboard-shortcut

Usage

Describe the complete key combination with keys. Use onTrigger for the action; editable fields are ignored by default.

Examples

With sound

Optional key feedback using a local demonstration audio asset.

API reference

Custom NavUI keyboard shortcut component.

Keyboard Shortcut properties
PropTypeDefaultDescription
keysRequiredreadonly KeyboardShortcutKey[]—The event.key values to match, with optional React labels for the visible Kbd keys.
onTrigger(event: KeyboardEvent) => void—Called once when every configured key is held; it can open a command menu or run any shortcut action.
sound / soundVolumestring / number- / 0.5Optional audio URL and volume from 0 to 1. The sound plays as each matching key is pressed.
preventDefaultbooleantruePrevents the browser default only after the full shortcut is matched.
disabledbooleanfalseStops listening for the shortcut while preserving its visual presentation.
classNamestring—Classes merged onto the Kbd group, such as a custom gap.
keyClassName / pressedKeyClassNamestring / string- / focus-ring treatmentClasses applied to every key and to its active state. Use keyClassName for size-10 or raised shadows.
aria-labelstringGenerated from keysAccessible name for the displayed shortcut group.
allowInEditablebooleanfalseAllow shortcuts inside inputs, textareas, selects and contenteditable.

Accessibility

  • Uses the public SDK matchesShortcut helper for exact modifier chords. Editable fields and IME composition are ignored by default; allowInEditable is an explicit opt-in. Listeners are removed on unmount.