# CommandPalette

A modal search surface for navigating pages or running commands.

Connect Flood once using [the installation guide](https://flood.md/docs/installation). Then import the components you use; no per-component add command is needed.

## Example

```tsx
"use client";

import { FloodRoot, CommandPalette, Button } from "@flood-md/react";
import "@flood-md/react/styles.css";

export function Example() {
  return (
    <FloodRoot>
      <CommandPalette title="Go to page" searchLabel="Search pages" trigger={props => <Button {...props}>Go to page</Button>} items={[{id:"projects",label:"All projects"}]} onAction={id => console.log(id)} />
    </FloodRoot>
  );
}
```

## Design notes

- Choose comfortable or compact density. Items can be grouped, described or disabled.
- Opening focuses search. Enter or click runs an enabled action and requests closure. Escape and the close button return focus to the trigger.
- Use controlled query and loading for asynchronous search. The application owns requests, navigation and any global shortcut.

## API reference

| Prop | Values | Default |
| --- | --- | --- |
| `title` | `string` | `Required` |
| `trigger` | `(props: OverlayTriggerProps) => ReactNode` | `Required` |
| `open` | `boolean` | `—` |
| `defaultOpen` | `boolean` | `false` |
| `onOpenChange` | `(open: boolean) => void` | `—` |
| `disabled` | `boolean` | `—` |
| `closeLabel` | `string` | `—` |
| `closeOnOutsideClick` | `boolean` | `—` |
| `getFallbackFocus` | `() => HTMLElement \| null` | `—` |
| `searchLabel` | `string` | `Required` |
| `items` | `readonly CommandListItem[]` | `Required` |
| `density` | `"comfortable" \| "compact"` | `"comfortable"` |
| `query` | `string` | `—` |
| `defaultQuery` | `string` | `—` |
| `onQueryChange` | `(query: string) => void` | `—` |
| `onAction` | `(id: string) => void` | `Required` |
| `loading` | `boolean` | `—` |
| `placeholder` | `string` | `—` |
| `emptyMessage` | `string` | `—` |
| `loadingMessage` | `string` | `—` |
| `Native HTML props` | `Omit<Omit<HTMLAttributes<HTMLDialogElement>, "children" \| "title" \| "role">, "children" \| "description" \| "initialFocusRef">` | `Forwarded` |
