# Command Palette

VS Code–style command palette with fuzzy search



<ComponentPreview base="opentui" name="command-palette-demo" />

Installation [#installation]

<CodeTabs>
  <TabsList>
    <TabsTrigger value="cli">
      Command
    </TabsTrigger>

    <TabsTrigger value="manual">
      Manual
    </TabsTrigger>
  </TabsList>

  <TabsContent value="cli">
    ```bash
    npx shadcn@latest add @termcn/opentui-command-palette
    ```
  </TabsContent>

  <TabsContent value="manual">
    <Steps>
      <Step>
        Copy and paste the following code into your project.
      </Step>

      <ComponentSource base="opentui" name="command-palette" title="components/ui/command-palette.tsx" />

      <Step>
        Update the import paths to match your project setup.
      </Step>
    </Steps>
  </TabsContent>
</CodeTabs>

Usage [#usage]

```tsx
import { CommandPalette } from "@/components/ui/command-palette";
```

```tsx
<CommandPalette
  isOpen={true}
  onClose={() => setOpen(false)}
  commands={[
    { id: "save", label: "Save", onSelect: () => {} },
    { id: "quit", label: "Quit", onSelect: () => {} },
  ]}
/>
```

API Reference [#api-reference]

CommandPalette [#commandpalette]

| Prop          | Type         | Default               |
| ------------- | ------------ | --------------------- |
| `commands`    | `Command[]`  | `required`            |
| `isOpen`      | `boolean`    | `required`            |
| `onClose`     | `() => void` | `required`            |
| `placeholder` | `string`     | `"Type a command..."` |
| `maxItems`    | `number`     | `8`                   |

Command [#command]

| Prop          | Type         | Default    |
| ------------- | ------------ | ---------- |
| `id`          | `string`     | `required` |
| `label`       | `string`     | `required` |
| `description` | `string`     | -          |
| `shortcut`    | `string`     | -          |
| `onSelect`    | `() => void` | `required` |
| `group`       | `string`     | -          |
