# Advanced Search

> Search everything, or run a command, from one ⌘K dialog.

- Category: Navigation
- Import: `import { AdvancedSearch } from "@sagui/ui";`
- Page: /components/advanced-search

```tsx
import { useState } from "react";
import { AdvancedSearch, SearchTrigger } from "@sagui/ui";

export function Hero() {
  const [open, setOpen] = useState(false);
  return (
    <>
      <SearchTrigger onOpen={() => setOpen(true)} shortcut={false} />
      <AdvancedSearch
        open={open}
        onOpenChange={setOpen}
        scopes={[{ id: "all", label: "All" }, { id: "vendors", label: "Vendors", count: 2 }, { id: "orders", label: "Orders", count: 1 }]}
        results={[
          { id: "1", title: "Acme Supply", meta: "Vendor · New York", group: "Vendors", badge: { label: "Active", tone: "success" } },
          { id: "2", title: "Acme Logistics", meta: "Vendor · Newark", group: "Vendors" },
          { id: "3", title: "PO-10422", meta: "Order · Acme Supply", group: "Orders" },
        ]}
        commands={[{ id: "new", label: "Create vendor" }, { id: "theme", label: "Switch theme" }]}
      />
    </>
  );
}
```

## When to use

- App-wide search across records, with scopes, filters and a preview.
- Typing “>” to switch to commands.

## When not to use

- Use CommandPalette for commands only, and SearchField for one list.

## Installation

Install the package and import the styles once. The [installation guide](/docs/installation) covers the Tailwind setup.

```bash
npm install @sagui/ui
```

## Usage

```tsx
import { AdvancedSearch } from "@sagui/ui";

<AdvancedSearch open={open} onOpenChange={setOpen} results={results} scopes={scopes} onSelect={(r) => router.push(r.href)} />
```

## Accessibility

- The input is a `combobox` that controls a `listbox`, with `aria-activedescendant` on the active row.
- ↑ and ↓ move, Enter opens, ⌘/Ctrl+Enter opens in a new tab, Escape closes.
- Full screen on phones, with a Cancel button.
