Command
A searchable palette of actions that opens over the page, with an optional global shortcut.
SourceStyles source@monoline/react 0.4.0Markdown for AI toolsstable
- 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
| Prop | Type | Default | Description |
|---|---|---|---|
items required | CommandItem[] | – | The actions to list, each with an `id`, `label` and optional `group`, `keywords`, `hint`, `disabled` and `onSelect`. |
open | boolean | – | Whether the palette is open when controlled. Pair with `onOpenChange`. |
defaultOpen | boolean | false | Whether the palette starts open when uncontrolled. Default false. |
onOpenChange | ((open: boolean) => void) | – | Called with the new open state when the palette opens or closes. |
shortcut | string | – | A global key that toggles the palette, like `mod+k` (`mod` is Cmd on Mac, Ctrl elsewhere). |
title | string | 'Command palette' | Names the dialog. Visually hidden. |
placeholder | string | 'Type a command' | Placeholder text of the search box. Default "Type a command". |
emptyText | string | 'No results' | Message shown when no item matches the search. Default "No results". |
trigger | ReactNode | – | Optional trigger element, rendered as-is (use a Button with aria-haspopup="dialog"). |
className | string | – | Extra class name for the palette panel. |
Data Attributes
State is exposed through attributes. Style it with these selectors, not with class toggles.
| Attribute | Stylesheet |
|---|---|
[aria-disabled="true"] | command.css |
[data-active] | command.css |
CSS classes
| Class | Stylesheet |
|---|---|
.command | dialog.css |
.dialog-close | dialog.css |
.dialog-content | dialog.css |
.dialog-description | dialog.css |
.dialog-footer | dialog.css |
.dialog-header | dialog.css |
.dialog-overlay | dialog.css |
.dialog-title | dialog.css |
.drawer-content | dialog.css |
.command | command.css |
.command-empty | command.css |
.command-heading | command.css |
.command-hint | command.css |
.command-input | command.css |
.command-item | command.css |
.command-list | command.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
| Keys | Action |
|---|---|
| ArrowUp / ArrowDown | Move (skipping disabled items) |
| Home / End | Jump |
| Enter | Runs the item |
| Escape | Closes |