Components

Command

A searchable list of commands that ranks as you type, inline on a page or as a palette opened with a shortcut.

Usage

import {
  CommandDialog,
  CommandDialogContent,
  CommandEmpty,
  CommandInput,
  CommandItem,
  CommandList,
} from 'nyctoui/command'

<CommandDialog shortcut="mod+k">
  <CommandDialogContent>
    <CommandInput placeholder="Type a command…" />
    <CommandEmpty>No commands found.</CommandEmpty>
    <CommandList>
      <CommandItem onSelect={createIssue}>New issue</CommandItem>
      <CommandItem onSelect={openSettings}>Settings</CommandItem>
    </CommandList>
  </CommandDialogContent>
</CommandDialog>

An item’s text is what the search matches, so most items need no props beyond onSelect, which runs on a click and on Enter. Choosing an item closes the palette. mod in a shortcut is Command on Apple platforms and Ctrl elsewhere.

Good for

  • A ⌘ K palette in a project tool for jumping to any issue, page or setting.
  • Quick actions in a code editor or a design tool, searchable by name.
  • A “Move to” or “Assign to” picker inside a menu, filtering a long list of people or folders.
  • An admin console’s search across users, teams and billing accounts.

Anatomy

<CommandDialog>
  <CommandDialogTrigger />
  <CommandDialogContent>          {/* or <Command> on its own */}
    <CommandInput />
    <CommandLoading />
    <CommandEmpty />
    <CommandList>
      <CommandPage>                  {/* optional, for nested pages */}
        <CommandGroup>
          <CommandLabel />
          <CommandItem>
            <CommandShortcut>
              <Kbd />
            </CommandShortcut>
          </CommandItem>
        </CommandGroup>
        <CommandSeparator />
      </CommandPage>
    </CommandList>
    <CommandFooter>
      <CommandHint />
    </CommandFooter>
  </CommandDialogContent>
</CommandDialog>

Searching

Every word of the search has to match, in any order, and the best matches rise to the top. An exact match ranks first, then a prefix, then the start of a later word, then a match inside a word, then the letters in order with gaps, so gtst still finds “Go to settings”. Shorter values win ties, accents are ignored, and keywords rank just below the item’s own text. Keywords match only as unbroken runs, never as scattered letters, so a long description cannot match everything. Items written out in a list keep their order and only hide; items passed as data rank by score. Groups with no match hide, and so do separators while searching.

Pass filter to match another way, such as ui-sdk’s 'fuzzy', or wrap defaultFilter to boost recent items.

Keyboard

Focus stays in the input, so typing and moving never fight. UpDown move the highlight and wrap at the ends. Enter runs the item, or follows it when it is a link. Esc clears the search, then goes back a page; Backspace in an empty search goes back a page too.

Examples

Inline

Command on its own draws the same surface as a popup, for a picker set into a page or a popover. Disabled items show but are skipped.

Pass render={<Link to="…" />} for an item that navigates. Enter follows the link the way a click does. These items find pages by their descriptions too, through keywords.

Nested pages

Put each step in a CommandPage and give the item that opens it a page, such as picking a person after “Assign to…”. The search clears as a page opens and comes back when you go back. In a dialog, an item with a page keeps the palette open.

With filter={false}, the palette shows items as you give them. Pass status="loading" while the request is out, and a CommandLoading shows its spinner.

Thousands of items

For data rather than a written-out list, such as files, people or records, pass them to Command as items and use CommandVirtualList in place of CommandList, with a function that renders one row. The search covers every item and only the rows in view render, so 50,000 items cost about as much to show as 50. The arrow keys, Enter and the highlight work across the whole list, scrolled into view or not. The list is flat.

Reach for it past a few hundred items, or whenever the count has no limit. Below that, CommandList is the better fit: it takes groups, separators and pages.

Best practices

Do
  • Show useful items before anything is typed, such as recent pages or common actions.
  • Group results under labels like Pages, Actions and People so they scan quickly.
  • Add keywords to items people might search for by another name, such as “billing” for Payment methods.
  • Show each command’s shortcut with CommandShortcut, so people learn to skip the palette next time.
Don’t
  • Use a command palette for a short fixed list. A dropdown or a select is easier to find.
  • Make it the only way to reach an action. People who don’t know the shortcut need a visible route.
  • Put buttons or links inside an item. Each row is one option.

API reference

Command

The palette on its own: input, list and keyboard handling on one surface. Renders a <div>.

PropTypeDefault
onAction
Runs when any item runs, with its value. Return a promise to keep the item pending until it settles.
(value, details) => unknown—
query / defaultQuery / onQueryChange
Control the text in the input, for a server search.
string · (query, details) => void''
value / defaultValue / onValueChange
The value of the highlighted item. Without it, the first match is highlighted.
string | null · (value, details) => void—
pages / defaultPages / onPagesChange
The stack of open CommandPages, first to current.
string[] · (pages, details) => void—
items
Items as data, for a CommandVirtualList.
Array<{ value, label, keywords?, disabled? }>—
filter
Return 0 or false to hide an item. false shows the items as given, for results a server filtered.
(item, query) => number | boolean | 'fuzzy' | 'contains' | falseword filter
status
Whether results are loading, for CommandLoading and the list’s aria-busy.
'idle' | 'loading' | 'error''idle'
loop
Arrow keys wrap from the last item to the first.
booleantrue
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

CommandDialog

Wraps Dialog and accepts its props. Renders no element.

PropTypeDefault
shortcut
Opens and closes the palette from anywhere, e.g. mod+k or mod+shift+p.
string—
controller
Lets triggers outside the dialog open it, such as a sidebar button and a mobile top-bar button. Pass the same controller to each CommandDialogTrigger.
ReturnType<typeof createCommandDialogController>—
open / defaultOpen / onOpenChange
Control whether the palette is open.
boolean · (open, details) => void—

CommandDialogTrigger

A DialogTrigger. Renders a plain <button>.

PropTypeDefault
render
Replaces the <button>, e.g. render={<Button />}.
ReactElement | function—
controller
The dialog to open, for a trigger placed outside its CommandDialog.
ReturnType<typeof createCommandDialogController>—

CommandDialogContent

The palette window: a Command in a dialog popup, 560px wide. Takes the Command props. The search starts empty each time it opens.

PropTypeDefault
aria-label
Names the dialog for screen readers.
string'Command menu'
onAction
Runs when any item runs, with its value. Return a promise to keep the item pending until it settles.
(value, details) => unknown—
query / defaultQuery / onQueryChange
Control the text in the input, for a server search.
string · (query, details) => void''
value / defaultValue / onValueChange
The value of the highlighted item. Without it, the first match is highlighted.
string | null · (value, details) => void—
pages / defaultPages / onPagesChange
The stack of open CommandPages, first to current.
string[] · (pages, details) => void—
items
Items as data, for a CommandVirtualList.
Array<{ value, label, keywords?, disabled? }>—
filter
Return 0 or false to hide an item. false shows the items as given, for results a server filtered.
(item, query) => number | boolean | 'fuzzy' | 'contains' | falseword filter
status
Whether results are loading, for CommandLoading and the list’s aria-busy.
'idle' | 'loading' | 'error''idle'
loop
Arrow keys wrap from the last item to the first.
booleantrue
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

CommandInput

The search field. Renders an <input> in a header row; other props go to the <input>.

PropTypeDefault
placeholder
Hint shown while empty; also the label unless aria-label is set.
string'Search…'
icon
Shown before the field. null drops it.
ReactNodesearch icon
children
Shown after the field, such as an Esc keycap.
ReactNode—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

CommandList

The scrolling listbox. Labelled “Suggestions” unless you pass aria-label.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

CommandVirtualList

A CommandList for the Command’s items, rendering only the rows in view with TanStack Virtual. Renders the same listbox; other props go to it. Flat: no groups or separators.

PropTypeDefault
children
Renders one row of the matching items, usually a CommandItem, which takes its value and label from the item.
(item, index) => ReactNode—
estimateSize
Row height before a row is measured.
number32
overscan
Rows rendered past each edge of the view.
number8
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

CommandItem

One command. A <div> by default.

PropTypeDefault
onSelect
Runs when the item is clicked or chosen with Enter. preventDefault() keeps a palette open; a promise keeps the item pending.
(event) => unknown—
value
What onAction receives and the highlight refers to.
string—
label
What the search matches. Shortcuts are left out.
stringthe item’s text
page
The CommandPage choosing this item opens.
string—
keywords
Other words that find the item.
string[]—
icon
Icon before the label, tinted quieter than the label.
ReactNode—
disabled
Shown, but skipped by the arrow keys and never chosen.
booleanfalse
closeOnSelect
In a CommandDialogContent, close the palette once chosen.
booleantrue
render
Replaces the <div>, e.g. render={<Link to="/" />}.
ReactElement | function—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

CommandGroup

Items under a CommandLabel. Hidden while none of them match.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

CommandEmpty

Shown when nothing matches, and announced. Put it beside the CommandList.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

CommandLoading

A row with a spinner, shown while Command’s status is loading. Put it beside the CommandList.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

CommandPage

Items shown while this page is on top. Renders no element.

PropTypeDefault
value
The name an item’s page opens. Leave it out for the first page.
string—

CommandStatus

A live region for results. Pass a function of { count, loading } to show the count.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

CommandLabel, CommandSeparator, CommandShortcut, CommandFooter, CommandHint

A group heading, a hairline that hides while searching, a hint aligned to the end of an item, a row of key hints under the list (hidden on touch screens), and one hint in it. Each takes sx.