Xzero UI
Pro library

Expanding search

An icon that morphs into a search field with results beneath it.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui/expanding-search
Live · keyboard ready

When to use

When not to use

Installation

Register both Xzero UI namespaces in your project's components.json:

{
  "registries": {
    "@xzero-ui": "https://mcp.xzero.co.uk/r/{name}.json",
    "@xzero-ui-pro": "https://mcp.xzero.co.uk/r/pro/{name}.json"
  }
}
npx shadcn@4.23.0 add @xzero-ui/expanding-search

Install xzero-foundation once, and import @/components/xzero/foundation.css in your app root. No Xzero token is used by this snapshot. For sample portraits, photos, fonts, or logos, download https://mcp.xzero.co.uk/install-assets.mjs and run node xzero-install-assets.mjs <receiving-project>.

Usage

import { ExpandingSearch } from "@/components/xzero/expanding-search/expanding-search";

export function HeaderSearch() {
  const router = useRouter();
  return (
    <ExpandingSearch
      label="Search projects and docs"
      items={[
        { id: "p1", title: "Xzero website", group: "Projects", meta: "Updated today" },
        { id: "d1", title: "Motion tokens", group: "Docs", keywords: ["spring"] },
      ]}
      onSelect={(item) => router.push(`/items/${item.id}`)}
    />
  );
}

API reference

ExpandingSearch

An icon button that morphs into a search field with grouped, highlighted results beneath it.

PropTypeDefaultDescription
label (required)string–Names the button, field, and results, such as "Search projects and docs".
items (required)ExpandingSearchItem[]–{ id, title, meta?, group?, icon?, keywords? }. Filtered client-side by title and keywords.
suggestionsExpandingSearchItem[][]Shown before anything is typed, such as recent searches.
suggestionsLabelstring"Recent"Heading for suggestions.
placeholderstring–Field placeholder. Defaults to label.
onSelect(item: ExpandingSearchItem) => void–Called when a result is chosen; the field then folds back.
onExpandedChange(expanded: boolean) => void–Called when the field opens or folds.
expandedWidthnumber360Widest the field grows, never past its container.
maxResultsnumber6Most results shown.
anchor"start" | "end""end"Edge the button sits on; the field grows away from it.
emptyHintstring"Try a shorter word or check the spelling."Tip under the empty state.
classNamestring–Added to the root.

Keyboard interactions

KeysAction
Enter / SpaceOn the icon button, expands the field.
ArrowDown / ArrowUpMoves through results, wrapping.
EnterChooses the active result.
EscapeFolds the field back into the icon.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Also in text fields

Guidance for AI tools

Expanding search: An icon that morphs into a search field with results beneath it. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://ui.xzero.co.uk/llms.txt

Browse all components