Commands
Search and run application commands as a modal palette, an expanding toolbar search, or an inline search bar.
import { Commands } from '@uthereal/ui/commands'Commands playground
Overview
Commands renders a searchable list of application commands across three layouts that share one schema, filtering engine, and keyboard model. Typing filters items by label, description, meta, group label, and keywords. Pressing Enter runs the highlighted command, or the top match after typing.
| Layout | Idle appearance | Hotkey behavior | Idle list | Typical placement |
|---|---|---|---|---|
palette (default) | Closed until triggered | Toggles the modal dialog | All items (with recents or suggestions first) | Application-wide command dialog |
expanding | Circular icon button | Expands or folds the field | Suggestions or recents only | Headers and toolbars with limited horizontal space |
inline | Visible search field | Focuses the input | All items when focused (or plain search bar when items is empty) | Page headers, sidebars, and forms |
Use Commands to search actions or records quickly from the keyboard. For a fixed list of actions on one object, use a dropdown menu. To pick a form value from options, use Multiselect or Morph select.
Usage
'use client'
import { useState } from 'react'
import { Button } from '@uthereal/ui/button'
import { Commands } from '@uthereal/ui/commands'
export function AppCommands() {
const [open, setOpen] = useState(false)
return (
<>
<Button
label="Search commands"
icon="search"
onClick={() => setOpen(true)}
/>
<Commands
label="Command palette"
open={open}
onOpenChange={setOpen}
groups={[{ id: 'billing', label: 'Billing' }]}
items={[
{
id: 'new-invoice',
label: 'Create invoice',
icon: 'plus',
group: 'billing',
action: 'create_invoice',
keywords: ['bill'],
},
{
id: 'settings',
label: 'Open settings',
icon: 'settings',
action: 'open_settings',
shortcut: ['mod', ','],
},
]}
onAction={(action, itemId) => console.log(action, itemId)}
/>
</>
)
}The host owns command execution and state. Commands reports each chosen item through onSelect and onAction, and accepts controlled open, query, and recent props when state must persist outside the component.
Examples
The playground above demonstrates the default palette modal dialog. The examples below show the two non-modal layouts.
Expanding
The expanding layout rests as an icon button anchored to start, center, or end, then morphs into a search field up to expandedWidth (clamped to its container). Before typing, the panel displays suggestions or recent items only. Pressing Escape, running an item, or blurring with an empty query folds the field back into the button.
Inline
The inline layout renders a standard search field with a reserved clear slot and hotkey cap. Supplying items opens a grouped results panel beneath the field on focus. Omitting items renders a plain search input for host-owned filtering via query and onQueryChange.
Searching, suggestions, and recents
Matching joins label, description, meta, group label, and keywords and checks whether the normalized text contains the trimmed query, ignoring case and diacritics. Results preserve item order and are capped by maxResults while searching. Groups appear in the order of their first matching item; items without a group render under ungroupedLabel.
While the query is empty:
- Setting
recentLimitabove0lists recently run item IDs first underrecentLabel. Seed initial IDs withdefaultRecent, or control them withrecentandonRecentChange. - When recents are empty,
suggestionsappear undersuggestionsLabel. A suggestion may reuse an existing item ID as a quick path or define a standalone item with its ownaction.
API reference
These serializable arguments and defaults come directly from the component schema.
| Argument | Type / default | Description |
|---|---|---|
label | stringDefault: "Search" | Accessible name of the control and its search field, e.g. "Command palette" or "Search projects". |
hideLabel | booleanDefault: false | Hide the inline layout label visually when the context already names the field; it is still announced. |
items | CommandItem[]Default: [] | Up to 500 commands or search items: label, optional description, meta, icon, group, shortcut keys and keywords, and the action it sends. Each needs a stable, unique ID. |
groups | OptionGroup[]Default: [] | Group headings in display order. Items name a group by its ID; items without a group sit under ungroupedLabel. |
suggestions | CommandItem[]Default: [] | Items shown before typing, such as recent searches. They may name a listed item by ID or stand alone (Arc). |
suggestionsLabel | stringDefault: "Recent" | Heading of the suggestions. |
placeholder | stringDefault: "Search" | Hint shown in the empty search field. |
emptyLabel | stringDefault: "No results" | Message shown, and announced, when nothing matches. |
emptyDescription | stringDefault: "Try a shorter word or check the spelling." | Supporting line under the empty message. |
ungroupedLabel | stringDefault: "Actions" | Heading of the items without a group ("Actions", as in Arc). |
clearLabel | stringDefault: "Clear search" | Name of the button that clears the search; it appears once something is typed. |
resultsLabel | stringDefault: "Results" | Accessible name of the list of results ("Results", as Arc). |
closeLabel | stringDefault: "Close search" | Name of the Esc button that closes the palette dialog, and of the icon button the expanding layout folds into. |
layout | palette | expanding | inlineDefault: "palette" | palette (the default) opens a modal dialog on the hotkey; expanding morphs from an icon button into the field, folding back on Escape or when left empty; inline is a plain search bar that drops results beneath it while it has items. |
hotkey | KbdKey[] | nullDefault: ["mod","k"] | Keys as Kbd key names (mod is Command on macOS and Ctrl elsewhere), shown as a key cap. The palette opens and closes its dialog, the expanding field grows and folds, and inline focuses the search. Default Command/Ctrl+K; set null to disable the global hotkey. |
defaultOpen | booleanDefault: false | Initial open state of the dialog or the expanding field. Later argument edits do not reset an existing instance. |
defaultQuery | stringDefault: "" | Initial search text. Later argument edits do not reset a mounted instance. |
closeOnSelect | booleanDefault: true | Close the palette dialog after running an item. |
autoFocus | booleanDefault: false | Focus the search field when the control mounts, without scrolling to it (Arc), for a control that appears on demand. |
recentLimit | integerDefault: 0 | How many recently run items are listed first while the search is empty. 0 (the default; Arc has no recent list) turns it off. |
recentLabel | stringDefault: "Recent" | Heading of the recent items. |
defaultRecent | string[]Default: [] | Initial recent item IDs, most recent first, e.g. from a previous session. |
maxResults | integerDefault: 50 | Most results shown while searching. |
expandedWidth | integerDefault: 360 | The widest the expanding field grows, never past its container. |
anchor | start | center | endDefault: "end" | Edge the expanding icon button sits on, growing away from it, or centered growing evenly. |
loading | booleanDefault: false | Busy state while the host searches or loads results. |
size | sm | md | lgDefault: "md" | Search field and row density, as in the menus of the same size. |
variant | solid | soft | outline | ghostDefault: "outline" | Field surface of the inline layout; behavior is identical. |
clearable | booleanDefault: true | Show a clear button while there is a query; Escape clears it. |
loopFocus | booleanDefault: false | Wrap arrow-key navigation at the first and last items. |
disabled | booleanDefault: false | Blocks editing and activation. |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes use the same interactions. |
theme | CommandsTheme— | Color mode, accent, and tokens, including the popup list tokens shared with the menus and Select. See Theming. |
motion | none | subtle | expressiveDefault: "subtle" | Dialog and highlight animation preset. System reduced-motion preferences take precedence. |
motionOptions | CommandsMotionOptions— | Dialog transition, entrance and exit poses, the pointer highlight glide (indicator, the snappy spring by default; arrow keys slide it in 70ms), and the expanding width spring (morph, the morph spring growing and the smooth spring folding back). Exits run faster than entrances. Durations are milliseconds. |
dir | ltr | rtl— | Reading direction. Omit it to inherit the page direction. |
React integration
| Prop | Purpose |
|---|---|
onAction(action, itemId) | Handle a command or suggestion action in the host application. |
onSelect(item) | Receive the chosen CommandItem before onAction runs. |
query / onQueryChange(query) | Control the search text in any layout. |
open / onOpenChange(open) | Control the modal dialog (palette) or expanded field (expanding). |
recent / onRecentChange(recent) | Control recently run item IDs, most recent first. |
renderIcon(name, context) | Render custom decorative icons; context.slot is search, item, clear, or empty. |
tokens | CSS custom properties applied after resolved theme tokens on root and portals. |
portalContainer | Target container for the palette modal portal inside a top layer. |
preset | Application defaults overridden by explicit instance props. |
ref | Ref to the root panel (palette), morphing lane (expanding), or field (inline). |
className, style, native attributes | Forwarded to the component root element. |
Keyboard & accessibility
| Key | Interaction |
|---|---|
hotkey | Toggle the palette dialog, expand or fold expanding, or focus inline (default mod+k). |
| Type | Filter commands and reset the active highlight so Enter runs the top match. |
↓ / ↑ | Move the active highlight across enabled commands. |
Home / End | Jump to the first or last command (Page Up and Page Down match). |
Enter | Run the highlighted command, or the top match after typing. |
Tab | Move through focusable buttons in the search bar and command list. |
Escape | Clear a non-empty query when clearable is true; otherwise close the palette or fold expanding. |
When commands are present, the search input exposes role="combobox" with aria-expanded, aria-autocomplete="list", aria-controls, and aria-activedescendant linked to the listbox and active option so focus stays in the input while navigating. A pre-mounted role="status" live region announces result counts and empty states.
In palette, the dialog traps focus, names itself from label, and marks background content inert. In expanding, the hidden input is inert while collapsed so keyboard and touch users interact with one icon button. All spacing and edge anchoring (start, center, end) use logical CSS properties and mirror automatically under dir="rtl". High-contrast mode (forced-colors: active) maps borders, focus edges, and active row contrast to system colors.
Motion and theming
Commands animates with LazyMotion and m:
- Highlight & list: The active row highlight glides on the
snappyspring under the pointer (indicatoroverride) and slides over70msfor arrow keys. Filtered rows glide into place while the results frame tracks height changes on thesmoothspring. - Expanding morph: Opening widens the shell on the
morphspring (morphoverride) while interpolating the corner radius from a circle to--ui-radius. Folding back settles on thesmoothspring without overshoot. The results panel shares the shell width so it unfolds cleanly. - Palette dialog: Entrance and exit follow the modal motion family (
transition,enter,exitoverrides), with exits running faster than entrances. - Reduced motion &
motion="none": Underprefers-reduced-motion: reduce, travel, blur, scale, and width springs are removed in favor of short opacity crossfades. Settingmotion="none"makes every state change immediate.
theme accepts mode, accent, and token overrides from the core, control, and popupList groups plus surfaceRadius, overlay, borderStrong, and borderSubtle. Defaults follow the active recipe (studio or soft), size, and any surrounding UtherealProvider.
Composition
In an agent composition, Commands is a leaf component. Every action across items and suggestions must reference a host-registered action; the handler receives { componentId, itemId }. Recent item IDs persist in host state at /menus/instance-<id>/recent.
{
"type": "Commands",
"props": {
"label": "Command palette",
"layout": "palette",
"items": [
{
"id": "new-invoice",
"label": "Create invoice",
"icon": "plus",
"action": "create_invoice"
}
]
},
"children": []
}