shadcn.io is not affiliated with official shadcn/ui
Kbd examples · Shortcut
Command Palette Shortcut Kbd for React
The ⌘K shortcut that opens a command palette, as a key group.
⌘K has become the shortcut for search and command palettes across many apps. This React example shows ⌘ and K in a KbdGroup, the hint you'd put in a search field, a navigation bar or a palette's trigger button. Show Ctrl K instead on Windows and Linux.
Preview
Installation
FAQ
Why is ⌘K the command palette shortcut?
Apps like Slack, Linear and GitHub made it popular, and others followed so people could use the same key everywhere. K is easy to reach and wasn't taken by a common editing command in most web apps.
Should I show ⌘K or Ctrl K?
Show the one for the user's platform: ⌘K on macOS, Ctrl K elsewhere, and listen for both. The Platform-Aware Shortcut example switches the label.
How do I detect ⌘K?
Add a keydown listener to the document, check event.key for k together with event.metaKey or event.ctrlKey, call preventDefault and open the palette. Remove the listener when the component is removed.
Should ⌘K work inside text fields?
Usually yes: it's a modifier shortcut, so it doesn't type anything, and people expect to reach the palette from anywhere. The exception is a rich text editor that uses ⌘K to insert a link; there, let the editor have it.
Related
- Copy Shortcut KbdThe Ctrl C copy shortcut as a key group
- Complex Shortcut KbdA three-key Ctrl Shift P shortcut in one
- Save Shortcut KbdThe ⌘S save shortcut as a key group
- Key Sequence with Then KbdA Ctrl K chord, the word then, and a B
- Standard DialogA share dialog with a read-only link, a
- Paste Shortcut KbdThe Ctrl V paste shortcut as a key group