Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Key Binding Search Command Menu Block for React

A text editor's key map as a command menu shown open: type a command's name, or press Listen and the input takes keys instead and lists what is bound to them, says when nothing uses them and, in words, when two commands share them.

Framework
UI library

Preview

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Overview

Find a binding by pressing it with this key map command menu for React with Base UI. It opens from the Key map page of Keycastle, a text editor, whose header holds an outline field with its ⌘ K cap, and the editor is drawn under a soft scrim inside a hairline frame with a plus mark on each corner, a status bar at its foot. The menu is the catalog Command over thirty bindings in five groups, with their caps. Type a name and it filters. Press Listen, a Toggle, and the input stops taking text: it takes keys. Whatever you press is read from the key itself, so Option's characters do not matter, and is kept from doing what it normally does; it shows as caps in a band over the list, and the list shrinks to the commands bound to it, or says "Nothing uses ⌥ J. It's free." One binding, ⌘ D, is used twice and the band says so in words, "Two commands use it: Duplicate line and Select next match", while the rows that share keys carry the word Shared. Tab and Escape are never taken: Escape stops listening, Tab moves on. Choosing a command names it in the drawn editor's status bar; nothing runs. For preview the menu is drawn open in place when the page loads; the field, or Ctrl or ⌘ K while focus is in the block and it is not listening, opens the real command dialog with the same keymap and query. For editors, IDEs, design tools and any app people remap.

FAQ

Why is the menu already open, and what do I keep?

So you can see it without a click. On load the menu is the Command drawn inline over a picture of the editor, in a plain shell that is not modal, so nothing is trapped, hidden or focused and the page around the preview keeps working. The header's field opens the real command dialog, modal, with its focus trap, Escape and focus return, and the inline copy stays closed until a reload. Both show the same Palette and share the block's state, so what you typed in the copy is in the real dialog. In your app keep the dialog and drop the copy: the "in-place" state, the scrim with its shell and the Escape and blur effects.

How does the key capture work?

While Listen is pressed a capture listener above the band and the input reads every key down, builds a combo from the modifiers and event.code ("mod+shift+KeyZ"), stops the event so it neither types nor moves the list, and rowsFor lists the bindings with that combo. "mod" is Command on a Mac and Control elsewhere, so one keymap serves both. Keys that are only a modifier are ignored until a key joins them. In your app, the same combo strings are what you would match your keymap against.

Can I always get out of listening?

Yes, and that is why two keys are never captured: Tab, so the keyboard is never trapped in the field, and Escape, which stops listening and nothing more. In the copy and in the real dialog the first Escape (or a click away) only stops listening and says so; the next one closes the menu. Ctrl or ⌘ K is read as keys while listening, not as the shortcut that opens the dialog.

How is a shared binding shown?

boundTo lists the commands with the same combo. A row whose keys are shared carries the word Shared, never a colour, and the band and the spoken line say who: "Two commands use ⌘ D: Duplicate line and Select next match." Free keys are said just as plainly. The keymap is typed data here; in your app it would be your commands and their current bindings.

Is it accessible from the keyboard?

Yes. Type to search, the arrow keys move through the rows, Enter shows the highlighted one and Escape closes the menu and puts focus on the field; Ctrl or ⌘ K opens the dialog while focus is inside the block, and only then. The rows are options of a cmdk listbox; the block turns off its own fuzzy filter and lists the rows itself. What the keys found is said in the polite message inside the menu.

How does it look on a phone?

A phone has no key to press, so Listen is left out there and the band says that key capture needs a hardware keyboard; the text search works as it does everywhere. The copy shown on load docks to the top of the page at full width and the key hints go.

  • Pro

    A task app's shortcut sheet as a command menu shown open as a help popover at the corner: a Mac or Windows switch re-labels every key cap, groups fold from their heads, search filters by action name, and a button really copies the list as a Markdown table.

  • Pro

    Actions Command Menu

    Actions and keys

    A signing tool's document with its actions menu shown open: nine actions in four groups, a key on the five that change the document that runs them while the menu is open, and a drawn lease whose badge and signature follow.

  • Pro

    Editor Command Palette

    Search everything

    A code editor's palette shown open under its title bar: one box with four modes, files by default, then a first > for commands with their keys, @ for symbols, : for a line and ? for the modes, each a chip you drop with Backspace.

  • Pro

    Keyboard Shortcuts Settings

    Appearance and locale

    A keyboard shortcuts editor: twelve editor actions in three groups with their keys in Kbd caps, a Change button that records the next combination, a conflict check with Replace or Cancel, Changed marks and Reset, a search and a PC or Mac choice for the key words.

  • Pro

    Docs Search Command Menu

    Search everything

    A docs host's scoped search shown open under the header field: chips for All, Guides, Reference and Releases that carry how many pages match, and results with a path and one line of the page with the matched words marked.

  • Pro

    Basic Command Menu

    Search everything

    A team workspace's home page with its command menu shown open: eleven pages in three groups, a shortcut on the five most used, matches marked, an empty state that says what to try and a foot with the key hints and a spoken count.