Search Bar

An accessible, animated search field with a live suggestions dropdown, keyboard navigation, a clear button, a loading spinner, and a Cmd/Ctrl+K shortcut that focuses the input. It is a client component built on motion/react with inline-styled dark or light themes.

Search Bar
LIVE · running in a sandboxed iframe
Installed with plain shadcn add · no workarounds · theme neutral (none shipped)
See how it was built

Installation

pnpm dlx shadcn@latest add @reactframe/search-bar

Requires @reactframe in the registries of your components.json (shadcn adds official directory namespaces automatically).

Usage

usage.tsx
import * as React from "react"; import { SearchBar } from "@/components/ui/search-bar"; export default function Example() { return <SearchBar placeholder="Search components..." suggestions={["Button", "Card", "Dialog", "Input"]} onSearch={(value) => console.log(value)} />; }
  • Use as the primary search input in a site header, docs sidebar, or command-palette-style launcher that needs type-ahead suggestions from a known list.
  • Use when you want a keyboard-first search with ArrowUp/ArrowDown navigation, Enter to submit or pick, and Escape to clear or close.
  • Use when a visible Cmd/Ctrl+K shortcut hint and a global shortcut to focus the field are desirable.
  • Avoid when suggestions must come from a remote API with complex grouping, or when a full combobox with multi-select is required.

Examples

Basic uncontrolled search

Uncontrolled usage with a static list of suggestions and a submit handler.

basic-uncontrolled-search.tsx
import * as React from "react"; import { SearchBar } from "@/components/ui/search-bar"; const components = ["Accordion", "Alert", "Avatar", "Badge", "Button", "Card", "Dialog", "Input"]; export default function BasicSearch() { return <SearchBar suggestions={components} onSearch={(value) => console.log("search:", value)} />; }

Controlled value with change tracking

Controlled usage where the parent owns the query string and reacts to every change.

controlled-value-with-change-tracking.tsx
import * as React from "react"; import { SearchBar } from "@/components/ui/search-bar"; export default function ControlledSearch() { const [query, setQuery] = React.useState(""); return <div className="flex flex-col gap-2"><SearchBar value={query} onValueChange={setQuery} suggestions={["Button", "Badge", "Card"]} maxSuggestions={3} /><p className="text-sm text-muted-foreground">Current query: {query}</p></div>; }

Light theme with loading state

Light palette, custom accent color and size, and a spinner while results load.

light-theme-with-loading-state.tsx
import * as React from "react"; import { SearchBar } from "@/components/ui/search-bar"; export default function LoadingSearch() { const [loading, setLoading] = React.useState(false); return <SearchBar theme="light" accentColor="#2563EB" size={16} width={420} loading={loading} placeholder="Find a document" onSearch={() => { setLoading(true); setTimeout(() => setLoading(false), 1200); }} />; }

API reference

PropTypeDefaultDescription
valuestring—Controlled input value. When provided (not undefined), the component ignores internal state and relies on onValueChange.
defaultValuestring""Initial value for uncontrolled usage.
onValueChange(value: string) => void—Called whenever the text changes, including when the clear button is pressed or a suggestion is picked.
onSearch(value: string) => void—Called on Enter (or when a suggestion is picked) with the submitted value.
placeholderstring"Search components..."Placeholder text shown when the input is empty.
suggestionsstring[][]Candidate strings used to build the suggestions dropdown, filtered by case-insensitive substring match against the current text.
maxSuggestionsnumber6Maximum number of suggestions displayed at once.
shortcutstring"⌘K"Label shown in the keycap badge when the field is empty and unfocused. Pass an empty string to hide the badge.
enableShortcutbooleantrueWhether a global Cmd/Ctrl+K keydown listener focuses the input.
loadingbooleanfalseReplaces the search icon with an animated spinner and hides the shortcut badge.
disabledbooleanfalseDisables the input, dims the field to 50% opacity, and hides the clear button and suggestions.
theme"dark" | "light""dark"Selects the color palette for background, border, text, muted, menu, and shadow.
sizenumber15Base font size in px. Height, padding, icon sizes, and gaps scale proportionally from this value.
radiusnumber14Border radius in px for the field; the suggestions panel uses radius + 2 and options use radius − 4.
widthnumber360Width of the component in px.
accentColorstring"#F2A841"Color used for focus border, focus halo, spinner, search icon when focused, and highlighted match text. Must be a CSS color usable in color-mix().
classNamestring—Additional classes merged onto the outer wrapper via tailwind-merge.

Accessibility

  • The input has role="combobox" with aria-expanded reflecting whether the suggestions list is shown, aria-controls pointing to the listbox id, and aria-autocomplete="list".
  • aria-activedescendant points to the currently highlighted option id while navigating with ArrowUp/ArrowDown, so screen readers announce the active suggestion.
  • Suggestions use role="listbox" on the container and role="option" with aria-selected on each item.
  • The search icon, spinner, and close icon are decorative and marked aria-hidden="true"; the clear button has aria-label="Clear search".
  • The source does not expose an aria-label or id prop on the input, and the placeholder is not a reliable accessible name, so wrap the component in a visible or visually hidden label (for example a <label> element) when no visible label exists.
  • Escape closes the suggestions first, then clears non-empty text, then blurs the input, which gives keyboard users a predictable exit path.
  • Clicking the wrapper focuses the input, and option/clear mouse-down events call preventDefault so focus stays in the field.
  • Disabled state sets the native disabled attribute on the input, removing it from the tab order.
  • The rotating spinner is a visual indicator only; loading state is not announced to assistive technology by the component itself, so consider a separate aria-live status message if needed.

Docs written by anthropic:claude-haiku-5-5 from the registry source.

Use with Coding Agent

Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.

prompt.md
Use the "Search Bar" component (reactframe/search-bar) from its shadcn registry.1. Install it with: npx shadcn@latest add @reactframe/search-bar2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: value, defaultValue, onValueChange, onSearch, placeholder, suggestions, maxSuggestions, shortcut, enableShortcut, loading, disabled, theme, size, radius, width, accentColor, className.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport * as React from "react"; import { SearchBar } from "@/components/ui/search-bar"; export default function Example() { return <SearchBar placeholder="Search components..." suggestions={["Button", "Card", "Dialog", "Input"]} onSearch={(value) => console.log(value)} />; }```

Files & dependencies

  • registry/new-york/search-bar/search-bar.tsx
dependenciesmotionclsxtailwind-merge

Looks similar, elsewhere