Back to Components

Search Bar

A sleek, modern search bar with animated placeholder text that smoothly cycles through multiple prompts with blur transitions.

Preview

Loading...

Installation

Install the component using the CLI.

$npx shadcn@latest add https://ankurz.me/r/search-bar.json

Usage

Import the component:

import { SearchBar, SearchBarMinimal } from "@/components/search-bar"

Use it in your code:

<SearchBar
  placeholders={[
    "Search for anything...",
    "Try 'React components'",
    "Ask me anything..."
  ]}
  interval={2500}
  onSubmit={(value) => console.log(value)}
/>

Props

PropertyTypeDefaultDescription
placeholdersstring[]["Search...", "Type something...", "What are you looking for?"]Array of placeholder texts to cycle through.
intervalnumber3000Time in milliseconds between placeholder transitions.
onChangefunctionundefinedCallback fired when input value changes.
onSubmitfunctionundefinedCallback fired when form is submitted or Enter is pressed.
iconReactNodeSearch iconCustom icon to display (SearchBar only).
classNamestring""Additional CSS classes for the container.