Charcoal UI

Search Input

A search icon that springs open into a field. Escape clears and collapses it.

  • Category: Inputs
  • Licence: Free, MIT
  • Built with: React 19, Tailwind CSS 4, Motion
  • Dependencies: motion, clsx, tailwind-merge

Examples

Search Input

API reference

PropTypeDefaultDescription
value / onValueChangestring / (v: string) => void—
onSearch(value: string) => void—
widthnumber260

About Search Input

Search Input starts as an icon and springs open into a full field when you need it, then collapses again on Escape. It keeps headers and toolbars tidy while search stays one click or one key away.

Search Input is an input component for React 19, styled with Tailwind CSS 4 and animated with Motion. It drops into Next.js, Vite, Remix or Astro through the shadcn CLI as a single file you own.

When to use Search Input

  • Site and app headers with limited space.
  • Toolbars in tables and file browsers.
  • Mobile navigation bars.
  • Docs sites where search is secondary to navigation.

How it works

The width animates on a spring from the icon to the target width, and focus moves into the field as it opens. Escape clears the value first, then collapses; the field stays a real search input for autofill and accessibility.

It is a real form control: it has an accessible name, works with the keyboard alone, shows a visible focus ring and announces its state to screen readers. With prefers-reduced-motion on, it holds still or settles instantly instead of animating.

Customizing Search Input

Every prop is documented in the API reference above with its type and default. The ones you will reach for first are listed here.

The Customize panel next to the preview lets you change placeholder, width live, and the Code tab updates to match, so the snippet you copy already carries your values.

  • value / onValueChange (string / (v: string) => void).
  • width (number, default 260).

Goes well with Search Input

These inputs pieces share its tokens and motion language, so they sit together on one page without clashing.

  • Range Slider: Six animated React range sliders on one accessible core: inline, tick, fluid, wave, bubble and ruler
  • Button: An animated React button with six variants, spring press feedback and a width-stable loading state
  • Switch: An animated React toggle switch whose thumb stretches when pressed, like a real switch
  • Checkbox: An animated React checkbox: the check draws itself in, the box pops, indeterminate morphs to a dash
  • Radio Group: An animated React radio group with roving focus and a highlight that glides between card options

Install Search Input

npx shadcn@latest add https://charcoalui.com/r/search-input.json

Search Input is free and MIT licensed. The command copies search-input.tsx into components/ui and installs clsx, tailwind-merge; you can also copy the source from the Code tab by hand.

It pairs well with Clear Input, a Pro piece: A search field whose clear button dissolves the text word by word instead of blanking it.

Frequently asked questions

How do I install Search Input?
Run npx shadcn@latest add https://charcoalui.com/r/search-input.json. The shadcn CLI copies search-input.tsx into components/ui and installs motion, clsx, tailwind-merge. You can also copy the source from this page by hand.
Is Search Input free for commercial use?
Yes. Search Input is MIT licensed: use it in any personal or commercial project and change it however you like.
Does Search Input work with Next.js?
Yes. It is a client component for React 19 styled with Tailwind CSS 4, so it works in the Next.js App Router and Pages Router, Vite, Remix and Astro.
Can an AI coding agent install Search Input?
Yes. Connect the Charcoal UI MCP server (https://charcoalui.com/mcp) to Claude Code, Cursor or any MCP client; get_component returns Search Input's props and source and get_install_command returns the exact command.

Search Input as Markdown · llms.txt