# Global search

Search grouped workspace records, recent items and actions in one modal surface.

Access: pro. Category: Navigation. Kind: composite.

## When to use

- Use it when a page needs search grouped workspace records, recent items and actions in one modal surface.
- Choose it as the nav region when composing a page from independently reusable TidalUI sections.

## Alternatives

- Choose navigation-bar instead when responsive saas navigation with native links, actions and an in-flow mobile disclosure is the actual interface need, rather than global search.

## Setup for agents

Use React 19 and TypeScript. Initialize shadcn for your framework, then merge this exact entry into components.json:

```json
{
  "registries": {
    "@tidal-pro": {
      "url": "https://tidalui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${TIDALUI_TOKEN}"
      }
    }
  }
}
```

The namespace must be named **@tidal-pro** because transitive Pro dependencies use that namespace. Obtain an agent key from your active Pro account at https://tidalui.com/account. Keep TIDALUI_TOKEN in your local environment, never in components.json, client code, Git or logs.

```sh
export TIDALUI_TOKEN='your-private-agent-key'
npx shadcn@latest add @tidal-pro/waitlist-form
npx shadcn@latest add https://tidalui.com/r/tidal-button.json
```

Free command: `npx shadcn@latest add https://tidalui.com/r/<name>.json`.
Pro command: `npx shadcn@latest add @tidal-pro/<name>`.

Import the base stylesheet and every stylesheet listed on the installed item's metadata. For example:

```tsx
import "./components/ui/tidal.css";
import "./components/ui/hero-section.css";
// Place installed components inside this wrapper:
<div className="tidal-scope" data-theme="dark">...</div>
```

Omit data-theme for the default light theme. Put the attribute on the same tidal-scope element for dark mode. Every component installs the shared free tidal-base dependency. After upgrading, run `npx shadcn@latest add https://tidalui.com/r/tidal-base.json --overwrite` to receive current tokens. Review local modifications before overwriting.

Vite: Use React + TypeScript. Map @/* to ./src/* in paths and Vite resolve.alias. Import tidal.css and each component stylesheet in your application entry.

Next.js 15 App Router: Next.js App Router: import tidal.css and component CSS in app/layout.tsx. Interactive examples belong in a client component with "use client". Map @/* to ./* or ./src/* to match your project.

TypeScript 6: use paths without baseUrl:

```json
{
  "compilerOptions": {
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  }
}
```

Pro registry requests are server/CLI-only. Use the same-origin account interface in a browser; cross-origin Authorization preflights are intentionally unsupported.


## Install Global search

```sh
npx shadcn@latest add @tidal-pro/global-search
```

Stylesheets: `components/ui/tidal.css`, `components/ui/global-search.css`.

## Minimal example

```tsx
import"./components/ui/tidal.css";
import"./components/ui/global-search.css";
import{TidalGlobalSearch}from"./components/ui/global-search";
export default(p:Parameters<typeof TidalGlobalSearch>[0])=><div className="tidal-scope"><TidalGlobalSearch {...p}/></div>;
```

## Structured props

- `TidalGlobalSearch.description: ReactNode`: Required description value accepted by this exported component.
- `TidalGlobalSearch.groups: ReadonlyArray<TidalGlobalSearchGroup>`: Required groups value accepted by this exported component.
- `TidalGlobalSearch.onOpenChange: (open: boolean) => void`: Callback invoked when the open change interaction is proposed.
- `TidalGlobalSearch.onQueryChange: (query: string, event: ChangeEvent<HTMLInputElement>) => void`: Callback invoked when the query change interaction is proposed.
- `TidalGlobalSearch.open: boolean`: Required open value accepted by this exported component.
- `TidalGlobalSearch.query: string`: Required query value accepted by this exported component.
- `TidalGlobalSearch.title: ReactNode`: Required title value accepted by this exported component.
- `TidalGlobalSearch.closeButtonProps?: Omit<ButtonHTMLAttributes<HTMLButtonElement>, "type" | "aria-label" | "children" | "dangerouslySetInnerHTML"> | undefined`: Optional close button props value accepted by this exported component.
- `TidalGlobalSearch.closeButtonRef?: Ref<HTMLButtonElement> | undefined`: Optional close button ref value accepted by this exported component.
- `TidalGlobalSearch.closeLabel?: string | undefined` (default "Close search"): Optional close label value accepted by this exported component.
- `TidalGlobalSearch.defaultTriggerLabel?: ReactNode` (default "Open search"): Optional default trigger label value accepted by this exported component.
- `TidalGlobalSearch.defaultTriggerProps?: Omit<ButtonHTMLAttributes<HTMLButtonElement>, "children" | "dangerouslySetInnerHTML"> | undefined`: Optional default trigger props value accepted by this exported component.
- `TidalGlobalSearch.defaultTriggerRef?: Ref<HTMLButtonElement> | undefined`: Optional default trigger ref value accepted by this exported component.
- `TidalGlobalSearch.dir?: "ltr" | "rtl" | undefined`: Optional dir value accepted by this exported component.
- `TidalGlobalSearch.emptyContent?: ReactNode` (default "No matching results."): Optional empty content value accepted by this exported component.
- `TidalGlobalSearch.error?: ReactNode`: Optional error value accepted by this exported component.
- `TidalGlobalSearch.inputLabel?: string | undefined` (default "Search"): Optional input label value accepted by this exported component.
- `TidalGlobalSearch.inputPlaceholder?: string | undefined` (default "Search"): Optional input placeholder value accepted by this exported component.
- `TidalGlobalSearch.inputProps?: Omit<InputHTMLAttributes<HTMLInputElement>, "type" | "value" | "defaultValue" | "children" | "dangerouslySetInnerHTML"> | undefined`: Optional input props value accepted by this exported component.
- `TidalGlobalSearch.inputRef?: Ref<HTMLInputElement> | undefined`: Optional input ref value accepted by this exported component.
- `TidalGlobalSearch.loading?: boolean | undefined` (default false): Optional loading value accepted by this exported component.
- `TidalGlobalSearch.loadingLabel?: string | undefined` (default "Searching"): Optional loading label value accepted by this exported component.
- `TidalGlobalSearch.onResultSelect?: ((resultId: string, result: TidalGlobalSearchResult, event: MouseEvent<HTMLAnchorElement | HTMLButtonElement>) => void) | undefined`: Callback invoked when the result select interaction is proposed.
- `TidalGlobalSearch.overlayProps?: Omit<Omit<Dialog.DialogOverlayProps & RefAttributes<HTMLDivElement>, "ref">, "children" | "dangerouslySetInnerHTML" | "asChild" | "forceMount"> | undefined`: Optional overlay props value accepted by this exported component.
- `TidalGlobalSearch.overlayRef?: Ref<HTMLDivElement> | undefined`: Optional overlay ref value accepted by this exported component.
- `TidalGlobalSearch.portalContainer?: HTMLElement | null | undefined`: Optional portal container value accepted by this exported component.
- `TidalGlobalSearch.recentItems?: ReadonlyArray<TidalGlobalSearchResult> | undefined`: Optional recent items value accepted by this exported component.
- `TidalGlobalSearch.recentLabel?: string | undefined` (default "Recent"): Optional recent label value accepted by this exported component.
- `TidalGlobalSearch.resultsLabel?: string | undefined` (default "Search results"): Optional results label value accepted by this exported component.
- `TidalGlobalSearch.shortcutKeys?: ReadonlyArray<TidalShortcutKey> | undefined`: Optional shortcut keys value accepted by this exported component.
- `TidalGlobalSearch.showKeyboardHint?: boolean | undefined` (default true): Optional show keyboard hint value accepted by this exported component.
- `TidalGlobalSearch.theme?: "light" | "dark" | undefined` (default "light"): Optional theme value accepted by this exported component.
- `TidalGlobalSearch.trigger?: ReactElement<unknown, string | JSXElementConstructor<any>> | null | undefined`: Optional trigger value accepted by this exported component.

## Complete usage example

[Source](https://tidalui.com/examples/global-search.tsx) | [Manifest](https://tidalui.com/examples/global-search.json). Install the listed additional dependencies. Consumer fixture: TypeScript pass; Vite pass. This fixture check is distinct from the actual shadcn install receipt.

```tsx
"use client";

import "./components/ui/tidal.css";

import { useId, useMemo, useState, type MouseEvent } from "react";

import { FileText, FolderKanban, Settings2, UserRound } from "lucide-react";

import { TidalGlobalSearch, type TidalGlobalSearchGroup, type TidalGlobalSearchResult } from "./components/ui/global-search";

import "./components/ui/global-search.css";

import "./components/ui/keyboard-key.css";

import "./components/ui/spinner.css";



const tidalExampleStyles = ".tidal-scope .global-search-demo {\n  display: grid;\n  width: min(100%, 440px);\n  min-width: 0;\n  justify-items: start;\n  gap: 14px;\n  margin-inline: auto;\n}\n\n.tidal-scope .global-search-demo > p {\n  min-width: 0;\n  margin: 0;\n  color: var(--t-muted);\n  font-size: 11px;\n  line-height: 1.45;\n  overflow-wrap: anywhere;\n}\n\n.tidal-scope .global-search-demo > p:focus-visible {\n  outline: 2px solid var(--t-accent);\n  outline-offset: 3px;\n}";

export interface GlobalSearchDemoProps {
  theme?: "light" | "dark";
}

function isPlainPrimaryClick(
  event: MouseEvent<HTMLAnchorElement | HTMLButtonElement>,
) {
  return !(
    event.metaKey ||
    event.ctrlKey ||
    event.shiftKey ||
    event.altKey ||
    event.button !== 0
  );
}

export function GlobalSearchDemo({ theme = "light" }: GlobalSearchDemoProps) {
  const destinationId = `global-search-${useId().replace(/:/g, "")}`;
  const [open, setOpen] = useState(false);
  const [query, setQuery] = useState("");
  const [compact, setCompact] = useState(false);
  const [status, setStatus] = useState("No result selected.");

  const corpus = useMemo<TidalGlobalSearchGroup[]>(
    () => [
      {
        id: "workspace",
        label: "Workspace",
        results: [
          {
            id: "project-atlas",
            label: "Atlas planning",
            description: "Sample project",
            meta: "Project",
            icon: <FolderKanban />,
            href: `#${destinationId}`,
          },
          {
            id: "release-brief",
            label: "Release brief",
            description: "Sample document",
            meta: "Document",
            icon: <FileText />,
            href: `#${destinationId}`,
          },
          {
            id: "ava-reed",
            label: "Ava Reed",
            description: "Sample teammate",
            meta: "Person",
            icon: <UserRound />,
            href: `#${destinationId}`,
          },
        ],
      },
      {
        id: "actions",
        label: "Actions",
        results: [
          {
            id: "compact-view",
            label: compact ? "Use comfortable view" : "Use compact view",
            description: "Change this local sample",
            meta: "Action",
            icon: <Settings2 />,
          },
        ],
      },
    ],
    [compact, destinationId],
  );

  const groups = useMemo(() => {
    const normalizedQuery = query.trim().toLocaleLowerCase();
    if (!normalizedQuery) return corpus;
    return corpus.map((group) => ({
      ...group,
      results: group.results.filter((result) =>
        `${result.label} ${String(result.description ?? "")} ${String(result.meta ?? "")}`
          .toLocaleLowerCase()
          .includes(normalizedQuery),
      ),
    }));
  }, [corpus, query]);

  const recentItems = useMemo<readonly TidalGlobalSearchResult[]>(
    () => [corpus[0].results[0], corpus[0].results[1]],
    [corpus],
  );

  return (
    <section className="global-search-demo" aria-label="Global search preview">
      <TidalGlobalSearch
        open={open}
        onOpenChange={setOpen}
        query={query}
        onQueryChange={setQuery}
        groups={groups}
        recentItems={recentItems}
        title="Search workspace"
        description="Find a sample record or run a local view action."
        defaultTriggerLabel="Search workspace"
        shortcutKeys={[
          { id: "command", label: "⌘", accessibleLabel: "Command" },
          { id: "k", label: "K", accessibleLabel: "K" },
        ]}
        inputLabel="Search sample workspace"
        inputPlaceholder="Projects, documents, people, actions"
        theme={theme}
        onResultSelect={(resultId, result, event) => {
          if (!isPlainPrimaryClick(event)) return;
          if (result.href !== undefined) event.preventDefault();
          if (resultId === "compact-view") {
            const nextCompact = !compact;
            setCompact(nextCompact);
            setStatus(`Compact view ${nextCompact ? "on" : "off"}.`);
          } else {
            setStatus(`${result.label} selected.`);
          }
          setOpen(false);
        }}
      />
      <p id={destinationId} tabIndex={-1}>
        {status}
      </p>
    </section>
  );
}

export default function AgentExample() {
  return (
    <div className="tidal-scope" data-theme="light" dir="ltr">
      <style>{tidalExampleStyles}</style>
      <GlobalSearchDemo />
    </div>
  );
}

```

## Gotchas

- Install the declared registry dependencies and render inside a tidal-scope with the foundation stylesheet loaded.

## Theme and accessibility

{"tokens":["--t-accent","--t-border","--t-border-strong","--t-canvas","--t-danger","--t-display","--t-ease-out","--t-ease-spring","--t-faint","--t-font","--t-ink","--t-line","--t-muted","--t-primary","--t-primary-contrast","--t-radius-card","--t-radius-control","--t-radius-overlay","--t-radius-panel","--t-ring","--t-shadow-lg","--t-shadow-soft","--t-soft","--t-subtle","--t-surface","--t-wash"],"darkMode":true}

{"keyboard":["Tab and Shift+Tab follow the component's native focus order.","Arrow-key behavior follows the exported composite-control implementation.","Escape dismisses the open overlay where the underlying primitive supports dismissal."],"aria":"The component wires labels and relationships from consumer-provided visible text or ARIA props; preserve those labels in production.","notes":"Verify focus visibility, text alternatives, contrast, and reduced motion in the final composition."}

Required controlled open/onOpenChange, controlled query/onQueryChange(query,event), consumer-supplied globally unique grouped results, title and description. Optional recentItems shown only for an empty query, link or action result metadata/icons/disabled/native props, onResultSelect(id,result,MouseEvent), loading/error/empty states, trigger or default native trigger props/ref and nonfunctional shortcut hint, input labels/props/ref, close props/ref, overlay props/ref, content attributes/ref, portal container, theme, direction and keyboard-hint visibility. Native result anchors preserve href including an empty string, target/download/rel/modifiers and expose the original click event so hosts can explicitly own SPA routing. Native result/button handlers run first and prevention suppresses onResultSelect. Disabled or aria-disabled true results are nonoperable; explicit false is preserved. Search input ArrowDown/Up enters the result list; result ArrowUp/Down/Home/End moves native focus, skipping disabled rows. Radix Dialog owns modal focus, Escape, backdrop dismissal and trigger focus return. The component performs no search, filtering, request, navigation override, hotkey registration, storage or analytics.
