Playground

Command

A searchable palette of actions that opens over the page, with an optional global shortcut.

  • Built on native <dialog>
  • 2 parts, named exports
  • A modal dialog named by a hidden title; focus moves to the search input and returns to the opener on close.
  • The input is an ARIA combobox controlling a listbox of grouped options; focus stays in the input and aria-activedescendant names the active option.
  • ArrowUp and ArrowDown move (skipping disabled items), Home and End jump, Enter runs the item, Escape closes.
  • Styles in one file: dialog.css

Import

import '@monoline/css';
import {Command} from '@monoline/react';

Not installed yet? Pick a route.

Copies the source and its styles into your project.

npx monoline add command

Usage

import {Command, type CommandItem} from '@monoline/react';

const items: CommandItem[] = [
  {id: 'new', label: 'New file', group: 'File', hint: 'N'},
  {id: 'open', label: 'Open file', group: 'File', hint: 'O', keywords: ['browse']},
  {id: 'save', label: 'Save', group: 'File', hint: 'S'},
  {id: 'theme', label: 'Switch theme', group: 'View', keywords: ['dark', 'light']},
  {id: 'zoom', label: 'Zoom in', group: 'View'},
  {id: 'help', label: 'Open help'},
];

<Command
  shortcut="mod+j"
  items={items}
  trigger={<button type="button" className="btn btn-outline">Open palette</button>}
/>

Anatomy

Import the parts you need and nest them like this.

import {Command, matchesShortcut} from '@monoline/react';

<Command>
  <matchesShortcut />
</Command>

Examples

Palette

Press Ctrl or Cmd + J, or use the button. The docs search already owns Ctrl or Cmd + K.

Props

CommandProps

PropTypeDefaultDescription
items requiredCommandItem[]–The actions to list, each with an `id`, `label` and optional `group`, `keywords`, `hint`, `disabled` and `onSelect`.
openboolean–Whether the palette is open when controlled. Pair with `onOpenChange`.
defaultOpenbooleanfalseWhether the palette starts open when uncontrolled. Default false.
onOpenChange((open: boolean) => void)–Called with the new open state when the palette opens or closes.
shortcutstring–A global key that toggles the palette, like `mod+k` (`mod` is Cmd on Mac, Ctrl elsewhere).
titlestring'Command palette'Names the dialog. Visually hidden.
placeholderstring'Type a command'Placeholder text of the search box. Default "Type a command".
emptyTextstring'No results'Message shown when no item matches the search. Default "No results".
triggerReactNode–Optional trigger element, rendered as-is (use a Button with aria-haspopup="dialog").
classNamestring–Extra class name for the palette panel.

Data Attributes

State is exposed through attributes. Style it with these selectors, not with class toggles.

AttributeStylesheet
[aria-disabled="true"]command.css
[data-active]command.css

CSS classes

ClassStylesheet
.commanddialog.css
.dialog-closedialog.css
.dialog-contentdialog.css
.dialog-descriptiondialog.css
.dialog-footerdialog.css
.dialog-headerdialog.css
.dialog-overlaydialog.css
.dialog-titledialog.css
.drawer-contentdialog.css
.commandcommand.css
.command-emptycommand.css
.command-headingcommand.css
.command-hintcommand.css
.command-inputcommand.css
.command-itemcommand.css
.command-listcommand.css

Customization

Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.

app.css
.command {
  border-color: var(--accent);
}
.command[aria-disabled="true"] {
  background: var(--wash);
}

Accessibility

  • A modal dialog named by a hidden title; focus moves to the search input and returns to the opener on close.
  • The input is an ARIA combobox controlling a listbox of grouped options; focus stays in the input and aria-activedescendant names the active option.
  • ArrowUp and ArrowDown move (skipping disabled items), Home and End jump, Enter runs the item, Escape closes.
  • The shortcut prop toggles the palette from anywhere (mod is Cmd on Mac, Ctrl elsewhere); result count is announced through a status region.

Keyboard

KeysAction
ArrowUp / ArrowDownMove (skipping disabled items)
Home / EndJump
EnterRuns the item
EscapeCloses