Command

Search actions without turning them into a selected form value.
Download runnable sandbox
import { createSignal } from "solid-js";
import { Command, Dialog } from "@wsagency/radix2solid-primitives";
import styles from "./styles.module.css";
const actions = [
{ value: "note", label: "Create note" },
{ value: "protected", label: "Protected action" },
{ value: "details", label: "Open details" },
{ value: "unavailable", label: "Unavailable action", disabled: true },
];
export default function CommandDemo() {
const [inlineSearch, setInlineSearch] = createSignal("");
const [search, setSearch] = createSignal("");
const [open, setOpen] = createSignal(false);
const [details, setDetails] = createSignal(false);
const [acceptClose, setAcceptClose] = createSignal(true);
const [count, setCount] = createSignal(0);
const [submissions, setSubmissions] = createSignal(0);
const [lastAction, setLastAction] = createSignal("none");
let input!: HTMLInputElement;
let closeDetails!: HTMLButtonElement;
let transferFocus = false;
const select = (event: Event, value: string, inPalette: boolean) => {
if (value === "protected") event.preventDefault();
if (event.defaultPrevented) return;
if (inPalette && acceptClose()) setOpen(false);
setCount(current => current + 1);
setLastAction(value);
if (value === "details") {
transferFocus = inPalette;
setDetails(true);
}
};
return <div class={styles.Demo}>
<form onSubmit={event => { event.preventDefault(); setSubmissions(current => current + 1); }}>
<Command.Root search={inlineSearch()} onSearchChange={setInlineSearch}>
<Command.Input class={styles.Input} aria-label="Inline actions" placeholder="Search actions" />
<Command.List class={styles.List} aria-label="Inline action results">
<Command.Group>
<Command.Label class={styles.Label}>Actions</Command.Label>
{actions.filter(action => action.label.toLowerCase().includes(inlineSearch().trim().toLowerCase())).map(action =>
<Command.Item class={styles.Item} value={action.value} textValue={action.label} disabled={action.disabled} onSelect={event => select(event, action.value, false)}>{action.label}</Command.Item>)}
</Command.Group>
</Command.List>
<Command.Empty class={styles.Label}>No matching actions.</Command.Empty>
</Command.Root>
</form>
<Dialog.Root open={open()} onOpenChange={next => { if (next) { setSearch(""); transferFocus = false; } if (next || acceptClose()) setOpen(next); }}>
<Dialog.Trigger asChild>{target => target("button", { type: "button", class: styles.Button, children: "Open command palette" })}</Dialog.Trigger>
<Dialog.Portal>
<Dialog.Overlay class={styles.Overlay} />
<Dialog.Content class={styles.Content} onOpenAutoFocus={event => { event.preventDefault(); input.focus(); }} onCloseAutoFocus={event => { if (transferFocus) event.preventDefault(); }}>
<Dialog.Title>Command palette</Dialog.Title>
<Dialog.Description>Search actions. Protected action cancels before any side effect.</Dialog.Description>
<Command.Root search={search()} onSearchChange={setSearch}>
<Command.Input ref={input} class={styles.Input} aria-label="Palette actions" placeholder="Search actions" />
<Command.List class={styles.List} aria-label="Palette action results">
{actions.filter(action => action.label.toLowerCase().includes(search().trim().toLowerCase())).map(action =>
<Command.Item class={styles.Item} value={action.value} textValue={action.label} disabled={action.disabled} onSelect={event => select(event, action.value, true)}>{action.label}</Command.Item>)}
</Command.List>
<Command.Empty class={styles.Label}>No matching actions.</Command.Empty>
</Command.Root>
<Dialog.Close class={styles.Button}>Close palette</Dialog.Close>
</Dialog.Content>
</Dialog.Portal>
</Dialog.Root>
<Dialog.Root open={details()} onOpenChange={setDetails}>
<Dialog.Portal>
<Dialog.Overlay class={styles.Overlay} />
<Dialog.Content class={styles.Content} onOpenAutoFocus={event => { event.preventDefault(); closeDetails.focus(); }}>
<Dialog.Title>Action details</Dialog.Title>
<Dialog.Description>The action opened another modal without the palette stealing focus back.</Dialog.Description>
<Dialog.Close ref={closeDetails} class={styles.Button}>Close action details</Dialog.Close>
</Dialog.Content>
</Dialog.Portal>
</Dialog.Root>
<label><input type="checkbox" checked={acceptClose()} onChange={event => setAcceptClose(event.currentTarget.checked)} /> Accept palette close proposals</label>
<output aria-label="Command action count">Actions: {count()}</output>
<output aria-label="Command last action">Last action: {lastAction()}</output>
<output aria-label="Command search">Inline query: {inlineSearch() || "empty"}; palette query: {search() || "empty"}</output>
<output aria-label="Command form submissions">Form submissions: {submissions()}</output>
</div>;
}

Introduced in published 0.1.0-rc.3 and included in the current Primitives 0.1.0-rc.4 release, this native Solid component is not part of historical rc.2. Primitives is published on npm as 0.1.0-rc.4; use the exact-version installation instructions. Themes recipe.

Imports and anatomy

import { Command } from "@wsagency/radix2solid-primitives";
// Alternatively: import * as Command from "@wsagency/radix2solid-primitives/command";
export default () => <Command.Root>
<Command.Input aria-label="Actions" />
<Command.List aria-label="Action results">
<Command.Group>
<Command.Label>Workspace</Command.Label>
<Command.Item value="note" textValue="Create note" onSelect={() => console.log("Create note")}>Create note</Command.Item>
</Command.Group>
</Command.List>
<Command.Empty>No matching actions.</Command.Empty>
</Command.Root>;

API reference

PartProps and responsibility
Rootsearch/defaultSearch: string, onSearchChange(search), loop: boolean (default true). Search defaults empty. No selected value, open state, form name or global shortcut.
InputNative text input with combobox/listbox active-descendant semantics and aria-autocomplete="list". Value belongs to search state. Supply an accessible name.
ListResults listbox with a Root-owned ID. Supply an accessible name.
Group, LabelNamed result group, not a separate cursor.
ItemRequired stable value identity and plain-text textValue; optional disabled and cancellable onSelect(event). Native refs, consumer events and target-factory asChild apply.
EmptyNon-option status when zero result options are rendered, not when all results are disabled. Place beside List under Root, never inside the listbox.

Caller-owned filtering

Command never filters or ranks strings. Read controlled search and render your application results, as the demo does with ordinary label substring matching. Remote results are child updates, not a built-in loader. Search changes reset the active suggestion to the first enabled rendered result after that update. Other reorder preserves active identity; removal picks the next/previous enabled visible result or none.

All-disabled results remain visible results, with no active suggestion; they do not show Empty. Loading is a separate application status, also placed beside List rather than inside it. There is no fuzzy-search dependency, persisted selection, router or action scheduler.

Exactly-once actions and cancellation

An enabled Item emits one cancellable onSelect per deliberate Enter or pointer gesture. Later deliberate gestures can run it again. It is an action notification, not onValueChange; no committed value is retained. aria-selected means the transient active suggestion only.

Run a guard before side effects. event.preventDefault() cannot undo consumer code that already ran. The Dialog recipe guards first, returns if prevented, requests close, then executes one action. A parent refusing close must not suppress an otherwise accepted action. Inline Command does not close anything itself.

Keyboard and focus

DOM focus stays in Input. Up/Down wrap unless loop={false}. Enter dispatches the active action and prevents surrounding form submission, even with no active result. IME composition Enter never selects. Home/End, Left/Right and modified editing shortcuts stay native. IDs and active-descendant references follow mounted visible results; group labels and empty status never become options.

There is no global Ctrl/Cmd+K listener. Add an application shortcut only if your application needs one and owns its lifecycle.

Dialog composition

Dialog owns modality, title, description and focus restoration. Reset search explicitly on opening and focus Command.Input in onOpenAutoFocus; do not reset inline search on rerenders. When an action opens another modal, prevent palette close restoration from stealing its focus. The demo exposes action count, last action and surrounding form submission count, including protected cancellation and close refusal.

Native owner-scoped IDs and cleanup apply. Portal rendering follows Dialog's server/client lifecycle; this is not a guarantee of server-rendered modal contents or screen-reader certification. For a submitted single key, use Combobox, not Command.

Native source