Skip to Content
zjkm-ui
Components

Search Input

A search field with a clear button and a shortcut hint.

Props
<SearchInput />

Installation

npx shadcn@latest add https://ui.zjkm.tech/r/search-input.json
import { SearchInput } from "@/components/search-input"

Using JavaScript? Set tsx: false in components.json and the CLI converts it.

New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.

Usage

A search field with an icon, a clear button and a shortcut key shown at the end. Pressing the key anywhere on the page focuses the field, unless you're typing somewhere else. Escape clears it.

import { SearchInput } from "@/components/search-input";

export function DocsSearch({ onSearch }: { onSearch: (q: string) => void }) {
  return <SearchInput placeholder="Search docs" onChange={(e) => onSearch(e.target.value)} />;
}

Props

PropTypeDefaultDescription
labelstring"Search"Accessible name.
shortcutstring"/"Key that focuses the field. Empty for none.
classNamestringClasses for the wrapper.
...propsinput propsEvery native <input> prop: name, required, onChange and so on.

It has no animation, so reduced motion changes nothing.

On this page