Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Code Actions Command Menu Block for React

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.

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

See what is wrong with a line and fix it from the keyboard with this code actions command menu for React with Base UI. It opens from the editor in Tidyford, an editor extension, 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. The menu has two panes: a small code view of eight lines, three flagged with a wavy underline, whose line numbers are buttons in a ToggleGroup, and the catalog Command beside it (under it on a phone), which lists only what applies to the chosen line. A let that is never reassigned offers Use const, an import with a name nothing uses offers Remove unused import, and a line over 72 characters with a method chain offers Wrap lines; two Format rows, single quotes and trailing space, are always there. Each fix is a pure function of the document: choosing a row rewrites the line (a wrap makes several), marks what it wrote as changed, keeps the menu open and says what happened, and Ctrl or ⌘ Z, or the Undo button, puts the document back. The drawn editor behind the menu shows the same lines. 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, opens the real command dialog with the same document, line and history. For editors, linters and any tool that suggests a change to a line.

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 code view and the Command drawn inline under 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 the fixes you applied in the copy are in the document the dialog opens with. 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 list know what applies to a line?

Each check is a small function of the whole document and one line. The unused-import check lists the names inside the braces and drops those that no other line mentions as a whole word; the const check looks for a let whose name no other line assigns again; the wrap check needs a line longer than the limit with at least two calls chained by dots outside brackets and strings. The list is whatever those return for the chosen line, so choosing another line gives another list, and the flags in the code view come from the same functions.

How are the flagged lines shown without colour?

With a wavy underline in the text colour under the exact words at fault, and in words: a line's button is named with what is wrong ("Line 3, let retries is never reassigned") and the chosen line's problems are written under the code view. A line that was rewritten carries a bar at its start and the word "changed" in its name, and the line you chose has its number filled.

How does Undo work?

Every action pushes the document, the chosen line and what was rewritten onto a history before it applies, and Undo (the button, or Ctrl or ⌘ Z while focus is in the menu) pops it. The search field's own undo of typing is replaced by this while the menu is focused, and the button says nothing is left when the history is empty. An action with nothing to change, such as single quotes on a line with no double quotes, says so and adds nothing to the history.

What stays local, and how do I wire it?

All of it. The document, the history and the changes are state in the block; nothing is saved, linted or run. In your app replace START_TEXT with the buffer, keep problemsOf and allRows as the place your own checks plug in, and apply the result of apply through your editor's transaction so its undo and collaboration keep working.

Is it accessible from the keyboard?

Yes. Tab reaches the line buttons (a group: the arrow keys move between lines and Space chooses one), type in the search field to filter the list, the arrow keys move through it, Enter applies, 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. The code is read left to right in every direction of page.

  • 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

    A notes editor's formatting menu shown open over a note: a real textarea with a sample sits above seven rows that format its selection or insert a block, and a preview and a mono line show the result.

  • Pro

    A support inbox's quick edit as a command menu shown open under a ticket's header: pick a field, edit it in the right control, see Before and After, and Enter saves into the record card.

  • Pro

    A help desk's reply library as a command menu shown open over a ticket: choosing a reply with slots turns the menu into a short form, a textarea previews the filled reply, and Enter inserts it.

  • Pro

    A debugger's variables as a command menu docked at the end beside the code: Local, Closure and Global variables with type words and values, a Step button that advances three typed frames and marks what changed in words with the old value struck, and a changes-only switch.

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