Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Editor Command Palette Block for React

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.

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

Open files, run commands and jump around code from one box with this editor command palette for React with Base UI. It opens from Redwren, a code 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 title bar, three tabs, an explorer and twelve lines of code. The palette is the catalog Command and starts as a file search with the recent files first. A first > turns into a Commands Badge in front of the input and lists commands with their keys, @ lists the symbols of the open file, : takes a line number and moves the caret, and ? lists the four modes, which you can choose without closing the box. Backspace on an empty box drops the chip. Choosing a file switches the drawn tab and title, a symbol or a line moves the caret, and Toggle sidebar, Next tab and Previous tab change the drawing; the status line says what happened and that nothing is edited. The letters you typed are marked with Search Highlight Text and the foot counts the rows in each mode. For preview the palette is drawn open in place when the page loads; the field, or Ctrl or ⌘ K while focus is in the block, opens the real command dialog with the same rows, mode and query. For editors, IDEs and any tool with files and commands.

FAQ

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

So you can see it without a click. On load the palette 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 component and share the block's state, so the mode and the text you typed in the copy are 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 do the modes and the chip work?

The block keeps the mode apart from the text. In the plain file search a first >, @, : or ? is taken out of the input and becomes the mode, shown as a chip in front of it, so the input holds only what you search for. Backspace on an empty input drops the chip and goes back to files; Escape closes the palette. The ? mode lists the four modes as rows, and choosing one switches to it without closing. rowsFor returns the rows of the current mode, so a new mode is one function and one entry in MODES.

What does the line mode do with a number?

It shows one row, "Go to line 7", for a number from 1 to 12, the length of the drawn file; a bigger number reads "Go to the last line, 12" and says it is past the end, and anything that is not a number shows what to type. Choosing the row moves the drawn caret there. In your editor read the line count from the open document.

Do the keys on the command rows work?

They are shown as data, the way an editor lists its own bindings: Toggle sidebar says ⌘B, and the demo does not bind it. Choosing the row runs the command here. The keys read Ctrl or Alt on systems that are not Apple's, swapped in after the page loads. In your app show the bindings your editor really has.

What stays local, and how do I wire it up?

Everything. Opening a file moves it to the front of the recent list and switches the drawn tab; Toggle sidebar hides the drawn explorer, Next tab and Previous tab move between the three tabs, and the rest of the commands only say what they would do. In your app replace pick with calls to your editor: open the file, run the command, move the cursor.

Is it accessible from the keyboard?

Yes. Type to search, the arrow keys move through the rows, Enter chooses and Escape closes the palette and puts focus on the field; Ctrl or ⌘ K opens the dialog while focus is inside the block, and only then. The count is spoken a moment after typing stops, and a mode change says its name. The rows are options of a cmdk listbox; the block turns off its own fuzzy filter and lists the rows itself. The real dialog is named by its title and described by its sentence.

  • 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.

  • Pro

    A cloud drive's quick open as a command menu shown open at the top of a file manager: recent files first, a search across every folder, middle-shortened paths with sizes and dates, kind chips and a sort, and the chosen row selected in the table behind.

  • Pro

    A code editor's snippet library as a command menu shown open over the editor: a language switch, a pane that follows the highlighted snippet with highlighted code and Copy, and Enter inserts it into the buffer.

  • 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

    An editor extension's quick fixes as a command menu shown open over the editor: a small code view with flagged lines and numbered line buttons, and a list of only the fixes that apply to the chosen line.

  • Pro

    A navbar for a notes app with a field-looking button and a shortcut that open a command palette: recent notes first, then pages, actions and settings in labelled groups, with the keys that work shown beside each row.