# CommandPalette

Modal ⌘K command palette — the L1 Dialog backdrop/overlay wrapping the L1 Combobox: grouped, searchable commands with icon/hash/kind sub-parts.

[All components](https://rickylabs.github.io/netscript/design-system/components/) · [Theme builder](https://rickylabs.github.io/netscript/create/) · [Implementation source](https://github.com/rickylabs/netscript/blob/main/packages/fresh-ui/registry/components/ui/command-palette.tsx)

## Live preview

[Open live command-palette preview](https://rickylabs.github.io/netscript/assets/fresh-ui/preview/?component=command-palette&theme=studio-utility)

## Install

```bash
netscript ui:add command-palette
```

## Usage and examples

The preview runs this JSX with the installed components. Import any composed primitives from your UI directory.

```tsx
import { useState } from 'preact/hooks';
import { Button } from '@app/components/ui/button.tsx';
import { CommandPalette } from '@app/components/ui/command-palette.tsx';

export function Example() {
  const [value, setValue] = useState('standard');
  const [open, setOpen] = useState(false);
  const [notice, report] = useState('');
  return (<><div><div><Button onClick={() => setOpen(true)}>Open commands</Button><CommandPalette open={open} onOpenChange={setOpen} groups={[{id:"orders",label:"Orders",items:[{id:"create",label:"Create order",onSelect:()=>report("Order created")}]}]} /></div></div><p role="status">{notice}</p></>);
}
```

## Props

Generated from native `deno doc --json --private` over the shipped implementation. Compound component props retain their owning interface; native attributes pass through where declared.

| Owner | Prop | Type | Optional | Description |
| --- | --- | --- | --- | --- |
| `CommandPaletteProps` | `open` | `boolean` | Yes |  |
| `CommandPaletteProps` | `onOpenChange` | `(open: boolean) => void` | Yes |  |
| `CommandPaletteProps` | `groups` | `CommandGroup[]` | No |  |
| `CommandPaletteProps` | `placeholder` | `string` | Yes |  |
| `CommandPaletteProps` | `emptyLabel` | `string` | Yes |  |
| `CommandPaletteProps` | `class` | `string` | Yes |  |
| `CommandPaletteProps` | `loading` | `boolean` | Yes |  |
| `CommandPaletteProps` | `loadingLabel` | `string` | Yes |  |
| `CommandPaletteProps` | `searchLabel` | `string` | Yes |  |
| `CommandPaletteProps` | `dialogLabel` | `string` | Yes | Localized accessible name of the modal. |
| `CommandPaletteProps` | `onQueryChange` | `(query: string) => void` | Yes | User edits only; async search and its results remain caller-owned. |
| `CommandPaletteProps` | `scrim` | `boolean` | Yes | False renders an inline surface without modal focus capture. |
| `CommandPaletteProps` | `filters` | `Renderable` | Yes |  |
| `CommandPaletteProps` | `footer` | `Renderable` | Yes |  |

```typescript
type CommandItemType = "page" | "section" | "action"
```

## Keyboard

| Key | Action |
| --- | --- |
| `ArrowDown/ArrowUp` | Navigate matching enabled options using the existing combobox active descendant. |
| `Home/End` | Highlight first/last matching enabled option. |
| `Enter` | Invoke the highlighted command once and request modal close; IME composition does not activate commands. |
| `Escape` | Request modal close once; controlled refusal preserves focus and options. Inline mode clears the query. |
| `Tab/Shift+Tab` | Native modal focus containment or inline control traversal; options remain in the active-descendant list, not the tab order. |

## Tokens

Semantic contract roles: `border/default`, `border/subtle`, `marker/default`, `radius/card`, `surface/card`, `surface/selected`, `surface/surface`, `text/fg`, `text/muted`.

CSS custom properties referenced directly: `--ns-bg`, `--ns-border`, `--ns-border-subtle`, `--ns-border-width`, `--ns-card`, `--ns-control-gap`, `--ns-control-height`, `--ns-fg`, `--ns-font-eyebrow`, `--ns-font-mono`, `--ns-font-sans`, `--ns-label-tracking`, `--ns-leading-body`, `--ns-leading-caption`, `--ns-leading-label`, `--ns-leading-small`, `--ns-leading-strong`, `--ns-marker`, `--ns-muted`, `--ns-muted-fg`, `--ns-overlay`, `--ns-radius-badge`, `--ns-radius-card`, `--ns-radius-control`, `--ns-ring`, `--ns-selected`, `--ns-shadow-md`, `--ns-size-icon-md`, `--ns-space-1`, `--ns-space-10`, `--ns-space-14`, `--ns-space-2`, `--ns-space-24`, `--ns-space-4`, `--ns-space-8`, `--ns-surface`, `--ns-surface-raised`, `--ns-text-body`, `--ns-text-caption`, `--ns-text-label`, `--ns-text-small`, `--ns-text-strong`, `--ns-tracking-body`, `--ns-tracking-caption`, `--ns-tracking-label`, `--ns-weight-body`, `--ns-weight-caption`, `--ns-weight-eyebrow`, `--ns-weight-label`, `--ns-weight-strong`.

## Contract and compatibility

Accessibility pattern: [WAI-ARIA guidance](https://www.w3.org/WAI/ARIA/apg/patterns/combobox/)

- Existing root and item fields remain supported; native DOM attributes do not pass through beyond class.
- Phase-one metadata correction: content/type/state describe derived output or item fields, not invented root props; excerpt/url/kind/shortcut are optional item content and filters/footer are slots.
- Headless data-state compatibility values remain unchanged; data-highlighted identifies current keyboard/pointer highlight.
- Local filtering matches label, url, excerpt, kind and hash text in source order; Pagefind/backend requests and navigation remain caller-owned.
- Disabled options remain visible but are excluded from headless arrow registration and activation. Empty/loading feedback is outside the listbox.
- Modal and inline composition share existing Dialog/Combobox; no new focus manager. Native IME editing is preserved.

Design contract values marked planned are not implementation props. The props above describe what ships today.
