shadcn.io is not affiliated with official shadcn/ui
Command Palette Dialog Block for React
A docs workspace's command palette shown open over its page: Recent and Pages when the field is empty, and a typed greater-than, at or hash turns it to Actions, People or Pages, each with its own groups and count, and each choice edits the drawn page.
Installation
Overview
Put every page, person and action behind one field, with this command palette for React with Base UI. It opens from the Workspace page of Folioway, a docs workspace: the header holds a search-field look-alike Button with its Kbd shortcut, and the page it searches is drawn under a soft scrim inside a hairline frame with a plus mark on each corner. The Command starts with Recent and Pages. Typing a prefix changes its mode: greater-than shows Actions, at shows People and hash shows Pages grouped by space. The prefix becomes a mode chip beside the field with a clear button, Backspace on an empty field leaves the mode, and each mode has its own groups, an empty state that names what was typed, and a count in the foot. Choosing a row does something to the drawn page: a page becomes its title, a person is mentioned in it, an action duplicates, locks, widens or annotates it. There is no Shine Button: Enter chooses. For preview the palette is drawn open in place when the page loads; the header button, or Command or Control and K while focus is in the block, opens the real palette, with the same field and the same rows. For docs, notes, project tools and any app with more places than its menus can hold.
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 catalog Command drawn in place over the page, inside a native dialog element that isn't modal, so nothing is trapped or hidden and the page around the preview keeps working; its field doesn't take focus. The header button, or the shortcut, opens the real palette in a modal Dialog with its focus trap, Escape and focus return, and the copy stays closed until a reload. Both show the same PaletteBody component and share the block's state, so what was typed in the copy is there in the real one. In your app keep the Dialog and drop the copy: the "in-place" state, the scrim and the dialog element inside the frame.
How do the prefixes work?
When the palette is in no mode and the first character typed is greater-than, at or hash, prefixOf turns it into a mode and keeps the rest as the search, so a pasted >lock lands in Actions already searching for lock. The mode shows as a chip beside the field. Its button clears the mode, and so does Backspace on an empty field; a prefix typed inside a mode is just text. groupsFor returns the groups each mode shows, so adding a mode is one more entry in PREFIXES and one more branch there.
Who filters, and how are results counted?
The block does, with a case-insensitive match on a row's name and its few words of meta, so every library shows the same rows. The Command runs with shouldFilter off, and the field is controlled with value and onValueChange. The foot reads the count back in words ("4 actions") in a polite live region inside the palette, so it is announced in the real modal too, and an empty result names what was typed.
What does choosing a row do, and how do I wire it up?
It runs against local state and says what it did in a polite status message: a page becomes the drawn page's title, a person's first name joins its row of mentions, Duplicate adds Copy of to the title, Lock and Wide layout toggle, and the callout appears under the title. Nothing is saved or sent, and nobody is notified. In your app route to the page, insert the mention into your editor, and call your own commands in choose; the rows' labels already follow the page's state (Unlock page, Narrow layout) because they are built from it.
Is it accessible from the keyboard?
Yes. The real palette is a dialog named by a hidden title, focus starts in the field, the arrow keys move through the rows, Enter chooses and Escape closes and returns focus to the header button. The shortcut is Command and K on a Mac and Control and K elsewhere, shown on the button after the page loads, and it works only while focus is inside this block, so it never competes with your site's own search. The chip is a button named Leave and the mode. The copy shown on load moves no focus; Escape inside it closes it and puts focus on the header button.
How does it look on a phone?
The copy shown on load docks to the top of the page, full width, with no corners at the top, because a keyboard would cover its foot. The keys in the foot are dropped to leave room for the count. The real palette keeps the Command dialog's own phone layout, also near the top.
Related
- Pro
Command Palette Navbar
SearchA 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.
- Pro
Command Palette FAQ
SearchA FAQ for a docs host with a working command palette: a search-field button with its shortcut opens a palette of questions by topic, and choosing one opens its row below.
- Pro
Command Palette Footer
Sitemaps and trailsA centred footer for a notes app with a search-or-jump button and Command K shortcut that open a palette listing the footer's own links by group.
- Pro
A markdown notes app with its keyboard shortcuts sheet shown open: 16 shortcuts in three columns drawn as keycaps, a Mac and Windows switch that rewrites the caps, a search, and a key tester that names any chord you press.
- Pro
An invoicing app's quick-actions dialog shown open: eight action tiles in two columns, a star on each that pins it into one of four slots at the top, arrow keys across the tiles and a letter that runs an action.
- Pro
Command Menu Features
App screensA live command menu for a workflow launcher: a search field that filters nine actions in three groups, with a preview pane that shows what the highlighted action will do.