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-shortcutUsage
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.
| Prop | Type | Default | Description |
|---|---|---|---|
keysRequired | readonly 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 / soundVolume | string / number | - / 0.5 | Optional audio URL and volume from 0 to 1. The sound plays as each matching key is pressed. |
preventDefault | boolean | true | Prevents the browser default only after the full shortcut is matched. |
disabled | boolean | false | Stops listening for the shortcut while preserving its visual presentation. |
className | string | — | Classes merged onto the Kbd group, such as a custom gap. |
keyClassName / pressedKeyClassName | string / string | - / focus-ring treatment | Classes applied to every key and to its active state. Use keyClassName for size-10 or raised shadows. |
aria-label | string | Generated from keys | Accessible name for the displayed shortcut group. |
allowInEditable | boolean | false | Allow 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.