Skip to content

Expanding search

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

SearchFieldMotion
npx shadcn@latest add @silicon-ui/expanding-search

Installation

With the shadcn CLI

npx shadcn@latest add @silicon-ui/expanding-search

Manually

  1. Install the dependencies

    npm install lucide-react motion
  2. Copy these files into your project

    • components/silicon-ui/expanding-search/expanding-search.tsx
    • components/silicon-ui/expanding-search/expanding-search.module.css
  3. Add the foundation, once per app, for the design and motion tokens

    npx shadcn@latest add @silicon-ui/silicon-foundation

Usage

usage.tsx
import { ExpandingSearch } from "@/components/silicon-ui/expanding-search/expanding-search";

API reference

PropTypeDefault
label*

Names the button, the field, and the results, such as "Search projects and docs".

string—
items*ExpandingSearchItem[]—
suggestions

Shown before anything is typed, such as recent searches.

ExpandingSearchItem[][]
suggestionsLabelstring"Recent"
placeholderstring—
onSelect(item: ExpandingSearchItem) => void—
onExpandedChange(expanded: boolean) => void—
expandedWidth

The widest the field grows. It never grows past its container.

number360
maxResultsnumber6
anchor

The edge the button sits on; the field grows away from it.

"start" | "end""end"
emptyHint

A short tip under the empty state.

string"Try a shorter word or check the spelling."
classNamestring—

Dependencies

npm
lucide-reactmotion
Registry
silicon-motion-tokens