Chip Search Bar

A docked search bar that widens and turns terms into removable chips.

Preview

"use client";

import { MorphingSearchChips } from "@/components/motion/morphing-search-chips";

const tiles = [
  "from-rose-400/40 to-orange-300/30",
  "from-sky-400/40 to-blue-400/30",
  "from-emerald-400/40 to-teal-300/30",
  "from-amber-300/40 to-rose-300/30",
  "from-pink-400/40 to-rose-300/30",
  "from-teal-300/40 to-sky-300/30",
];

export function MorphingSearchChipsPreview() {
  return (
    <div className="relative flex h-[440px] w-full max-w-2xl flex-col justify-end overflow-hidden rounded-3xl border border-border bg-muted/40 p-4">
      <div aria-hidden="true" className="absolute inset-4 grid grid-cols-3 gap-3 opacity-80">
        {tiles.map((tile) => (
          <div key={tile} className={`rounded-2xl bg-gradient-to-br ${tile}`} />
        ))}
      </div>
      <MorphingSearchChips
        className="mx-auto"
        placeholder="Search inspiration"
        label="Search inspiration"
        defaultChips={["onboarding"]}
        defaultRecents={["dashboards", "empty states", "pricing pages"]}
        storageKey="beui:morphing-search-chips:recents"
        maxChips={4}
        suggestions={[
          "dashboards",
          "data tables",
          "dark mode",
          "empty states",
          "onboarding",
          "pricing pages",
          "settings",
          "sign in",
        ]}
      />
    </div>
  );
}

Install

Add it with the shadcn CLI, or copy the source manually.

$ bunx --bun shadcn add @beui/morphing-search-chips

API Reference

chips?
string[]

Active filters shown as chips inside the bar.

Default—
defaultChips?
string[]

The initial chips when uncontrolled. Default: []

Default[]
onChipsChange?
((chips: string[]) => void)

Called with the full list when a chip is added or removed.

Default—
query?
string

Text in the field.

Default—
defaultQuery?
string

The initial field text when uncontrolled. Default: ""

Default
onQueryChange?
((query: string) => void)

Called with the new text when the field changes.

Default—
recents?
string[]

Recent searches, newest first.

Default—
defaultRecents?
string[]

The initial recent searches when uncontrolled. Default: []

Default[]
onRecentsChange?
((recents: string[]) => void)

Called with the full list when a recent search is added or removed.

Default—
storageKey?
string

Persist uncontrolled recents in localStorage under this key.

Default—
maxRecents?
number

How many recent searches to keep. Default 5.

Default5
suggestions?
string[]

Terms offered while typing.

Default[]
filter?
false | ((term: string, query: string) => boolean)

How suggestions match the query. Default: case-insensitive substring. Pass `false` when `suggestions` already arrive filtered, e.g. from a server.

Default—
maxSuggestions?
number

How many matches to list under the typed query. Default 6.

Default6
loading?
boolean

Suggestions are being fetched.

Defaultfalse
maxChips?
number

Most chips allowed at once.

Default—
normalize?
((term: string) => string | null)

Clean a term before it becomes a chip; return null to reject it.

Default—
emptyState?
ReactNode

Shown when the field is empty and there are no recent searches.

Default—
side?
"auto" | "top" | "bottom"

Which way the surface grows. "auto" grows up unless there is no room. Default "top".

Defaulttop
open?
boolean

Whether the suggestions panel is open, for controlled use.

Default—
defaultOpen?
boolean

Whether the panel starts open when uncontrolled. Default: false

Defaultfalse
onOpenChange?
((open: boolean) => void)

Called with the new open state when the panel opens or closes.

Default—
disabled?
boolean

Dims the bar and blocks typing, chip removal and the panel. Default: false

Defaultfalse
name?
string

Submit each chip with a form under this name.

Default—
placeholder?
string

Hint text in the empty field. Default: "Search"

Default—
label?
string

Accessible name for the search field.

Default—
actions?
ReactNode

Trailing controls inside the bar, such as filter buttons.

Default—
className?
string

Classes merged onto the root element.

Default—
labels?
Partial<{ placeholder: string; label: string; suggestions: string; recent: string; recentSearches: string; clear: string; searching: string; removeFilter: string; hint: string; filterLimit: string; ... 4 more ...; filterMarked: string; }>

Override any built-in string.

Default—

More in Morphing Search

Keep in mind

Some components on this site are inspired by or recreated from existing work across the web. I'm not here to take credit; just to learn, experiment, and sometimes push things a bit further. If something looks familiar and I forgot to mention you, reach out and I'll fix that right away.

Updated