Skip to content
shadcn.io

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.

Framework
UI library

⌘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

Preview width
⌘K

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

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.

What if ⌘K conflicts with the browser?

Some browsers use Ctrl K on Windows and Linux to search from the address bar. Calling preventDefault in your handler keeps it in the page. Shortcuts the operating system reserves can't be overridden, so avoid those.

Can people open the palette without the shortcut?

They must be able to: give the palette a visible trigger, such as a search button that shows the ⌘K caps. The shortcut is a faster way in, not the only one.