# CommandPalette

> A modal command search, the classic Ctrl+K palette.

- Category: [Overlays](https://tarve.dev/docs.md#overlays)
- Import: `import { CommandPalette } from "@tarve/core";`
- Props type: `CommandPaletteProps`
- Source: [packages/core/src/popups.ts:772](https://github.com/omarcosr/tarve/blob/main/packages/core/src/popups.ts#L772)

## Usage

```tsx title="CommandPalette.tsx"
import { Button, CommandPalette } from "@tarve/core";

let open = true;
let query = "";

<>
  <Button variant="outline" onClick={() => (open = true)}>
    Open command palette
  </Button>
  <CommandPalette
    id="palette"
    open={open}
    query={query}
    placeholder="Type a command…"
    items={[
      { value: "new", label: "New file", keywords: ["create"] },
      { value: "theme", label: "Toggle theme" },
      { value: "quit", label: "Quit" },
    ]}
    onOpenChange={(next) => {
      open = next;
    }}
    onQueryChange={(next) => {
      query = next;
    }}
    onSelect={(value) => console.log(value)}
  />
</>
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `open` (required) | `boolean` | — |  |
| `closeOnOverlay` | `boolean` | `true` |  |
| `closeOnSelect` | `boolean` | `true` |  |
| `onOpenChange` | `(open: boolean) => void` | — |  |
| `onSelect` | `(value: string) => void` | — |  |
| `width` | `number` | `520` |  |

### Inherited from `CommandProps`

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `id` (required) | `string` | — |  |
| `items` (required) | `readonly CommandItem[]` | — |  |
| `query` (required) | `string` | — |  |
| `emptyText` | `string` | — |  |
| `onEscape` | `() => void` | — |  |
| `onQueryChange` | `(query: string) => void` | — |  |
| `onValueChange` | `(value: string) => void` | — |  |
| `placeholder` | `string` | — |  |
| `value` | `string` | — |  |

## Common props

Shared by every component (descriptions: https://tarve.dev/docs.md#common-props): `children`, `class`, `className`, `highlight`, `key`, `motionFrom`, `onHighlight`, `onPaste`, `onPointerLeave`, `onPointerMove`, `onSize`, `onTransitionEnd`, `rovingGroup`.

## Types

```ts title="CommandItem"
interface CommandItem {
  value: string;
  label: string;
  keywords?: readonly string[];
  icon?: IconName;
  group?: string;
  shortcut?: string;
  disabled?: boolean;
}
```

Previous: [Command](https://tarve.dev/docs/components/Command.md) · Next: [Tabs](https://tarve.dev/docs/components/Tabs.md)

---

Tarve v0.13.8 · HTML version: https://tarve.dev/docs/components/CommandPalette · Index for agents: https://tarve.dev/llms.txt
