Search

Inputs
Navigation

A dedicated search input component with icon, clear button, loading state, and keyboard shortcut hints.

Preview

Interactive search examples

Basic Usage

Simple search input

Variants

Different visual styles

Default

Filled

Ghost

Sizes

Available search input sizes

Keyboard Shortcut

Show keyboard shortcut hint

Loading State

Search with loading spinner

Custom Icon

Search with custom icons

Without Icon

Minimal search without icon

Without Clear Button

Search without clear button

Props

Search component API reference

PropTypeDefaultDescription
variant'default' | 'filled' | 'ghost''default'Visual style variant
size'sm' | 'md' | 'lg''md'Size of the search input
onSearch(value: string) => voidCallback when the search value changes
onClear() => voidCallback when the clear button is clicked
loadingbooleanfalseShow loading spinner
iconReact.ReactNodeCustom icon (defaults to search icon)
hideIconbooleanfalseHide the search icon
clearablebooleantrueShow clear button when there's a value
shortcutstringKeyboard shortcut hint (e.g., "⌘K")
containerClassNamestringAdditional classes for the container

Usage

Import and implementation example

import { Search } from '@/components/ui/search'

export default function Example() {
  const [value, setValue] = useState('')
  const [loading, setLoading] = useState(false)

  const handleSearch = (searchValue: string) => {
    setValue(searchValue)
    if (searchValue) {
      setLoading(true)
      // Perform search...
      setTimeout(() => setLoading(false), 1000)
    }
  }

  return (
    <Search
      placeholder="Search..."
      value={value}
      onSearch={handleSearch}
      onClear={() => setValue('')}
      loading={loading}
      shortcut="⌘K"
    />
  )
}

Features

Built-in functionality

  • 3 variants: Default, filled, and ghost styles
  • 3 sizes: Small, medium, and large
  • Loading state: Built-in spinner animation
  • Clearable: Clear button appears when there's a value
  • Keyboard shortcut: Display shortcut hint (hidden when typing)
  • Custom icon: Replace the default search icon
  • Escape to clear: Press Escape to clear the input
  • Dark mode: Full dark mode support

Accessibility

ARIA support and keyboard navigation

ARIA Attributes

role="searchbox"aria-label (automatic from placeholder)aria-label on clear button

Keyboard Navigation

KeyAction
EscapeClear the search input
TabMove focus to/from input and clear button

Notes

  • Uses type="search" for native search semantics
  • Clear button is keyboard accessible
  • Focus ring indicates current focus
  • Loading state is visually indicated