App components / Command menus
Command menu
Search everything and act on it without leaving the keyboard. A tray holding a raised card: the search and grouped results in the card, the keys on the tray. ⌘K opens it from anywhere.
Code
The component itself, ready to drop into your project. Switch between React, Vue and plain HTML; every version uses the same Tailwind classes on Ochre's tokens.
Installation
Examples
Pick and act
A focused menu for one job: assigning an issue, with hints on the right.
Sizes
Command item rows from S to XXL. The highlighted row is State=Active.
With preview
The highlighted result previews on the right.
Scoped
Narrowed to Projects. Backspace in the empty field widens it to everything.
With answer
Ask a question ending in ? and the answer sits above the results, sources included.
Try: how do invoices round?
Motion
Built on Ochre's ease-out curves. With reduced motion switched on, everything still works, it just doesn't move.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| open | boolean | – | Whether it's showing. |
| onOpenChange | (open: boolean) => void | – | Called by the hotkey, esc, a click outside, or after running an item. |
| groups | { label: string; items: CommandItem[] }[] | – | Results under mono group labels, in order. |
| item.label / keywords | string, string[] | – | What it's called, and other words that should find it. |
| item.icon / hint / shortcut | ReactNode, ReactNode, string[] | – | Leading icon, a muted hint on the right, and its keys. |
| item.onSelect | () => void | – | Runs on ↵ or a click. |
| hotkey | string | false | "k" | ⌘ or Ctrl plus this key toggles the menu. false turns it off. |
| placeholder | string | "Type a command or search" | Placeholder in the search field. |
| emptyText | (query: string) => ReactNode | – | What to say when nothing matches. |
| footer | ReactNode | – | Replaces the key hints on the tray. |
| closeOnSelect | boolean | true | Keep it open for commands that lead to more commands. |
| size | "s" | "m" | "l" | "xl" | "xxl" | "m" | Command item rows at 32, 40, 48, 56 or 64 px, with type to match. |
| preview | (item: CommandItem) => ReactNode | – | Command menu with preview: the highlighted result beside the list. Hidden on phones. |
| scope / onScopeClear | { label, icon? }, () => void | – | Scoped command: a chip before the query. Backspace in an empty field or the chip's button clears it. |
| answer | (query: string) => { text, sources?, pending? } | null | – | Command with answer: an answer above the results, with numbered sources. |
| answerLabel | ReactNode | "Answer" | The mono label beside the star. |
| onQueryChange | (query: string) => void | – | Called as the query changes, to fetch answers or remote results. |
Usage
Use it for
- Apps with more places and actions than fit in the navigation.
- Power users who would rather type than click: jump to a project, assign, change status.
Avoid
- As the only way to reach something. Everything in it should also be findable with the mouse.
- Long descriptions in results. A label, a short hint and a shortcut are enough.