Skip to content

Search Input

Terminal-styled search input with / prefix and keyboard event callbacks. Supports controlled and uncontrolled modes.

Preview

Installation

$pnpm exec dgadd add ui/search-input
[Installs to]src/components/ui/search-input[Item]ui/search-input

dgadd is not public on npm yet. Until the first release, pack @diffgazer/add from the repository and install that tarball into this app, which is what puts dgadd on pnpm exec.

UI components require Tailwind CSS v4. Local copy mode imports src/styles/styles.css; package mode uses @diffgazer/ui CSS once packages are available.

Usage

tsx
import { SearchInput } from "@/components/ui/search-input";export default function SearchInputDefault() {  return <SearchInput placeholder="Search components..." />;}

Examples

Custom

Preview

Sizes, invalid, disabled

Preview

Keyboard Navigation

Preview

API Reference

SearchInput

NameTypeDefaultDescription
valuestringControlled search value.
defaultValuestring""Initial search value for uncontrolled usage.
onChange(value: string) => voidCalled with the next search value when the native input changes.
onEscape() => voidCalled when Escape is pressed and the event was not already handled.
onEnter() => voidCalled when Enter is pressed and the event was not already handled.
prefixReactNode"/"Prefix content before the input. Pass null to hide it.
clearLabelstring"Clear search"Accessible name for the clear button shown while the input has a value.
placeholderstring"Search..."Native placeholder. Also becomes the fallback aria-label unless aria-label is supplied.
size"sm" | "md" | "lg""md"Height/padding/font size token, shared with Input and InputGroup.
inputClassNamestringClasses merged onto the inner input. The public seam for styling the field itself (text overflow, alignment) instead of reaching through the shell with a `[&_input]` selector.
aria-labelstringplaceholderAccessible name forwarded to the native search input. Defaults to the placeholder text.
aria-invalidboolean | "true" | "false" | "grammar" | "spelling"Forwarded to the native search input and used by the wrapper for invalid styling.
disabledbooleanfalseDisables the native search input.

Accessibility

Keyboard Navigation

SearchInput provides onEscape and onEnter callback props. For arrow-key navigation in an adjacent list, use the onKeyDown prop or @diffgazer/keys's useNavigation hook. The search-input-keyboard example shows how to wire arrow keys via onKeyDown.

KeyAction
EscapeClears the current value when it is non-empty; otherwise calls onEscape when provided.
EnterCalls onEnter when provided.
ArrowRightWith the caret and selection at the end of a non-empty value, moves focus to the clear button; elsewhere it keeps its native caret move.
ArrowLeft (on the clear button)Returns focus to the search input.
Arrow keys / other keysForward through onKeyDown so a parent listbox, combobox, or custom search flow can own navigation.

With keyboard navigation

Preview

Notes

Controlled & Uncontrolled

Pass value + onChange for controlled mode. Pass defaultValue (or nothing) for uncontrolled mode. Works like every other @diffgazer/ui component via useControllableState.

Keyboard Callbacks

SearchInput provides onEscape and onEnter callback props for common search patterns (clear and submit). For arrow-key list navigation, use onKeyDown or @diffgazer/keys's useNavigation hook.

Custom Prefix

The prefix prop replaces the default / character with any ReactNode. Set prefix={null} to hide it entirely.

Size Variants

Pass size="sm", size="md" (default), or size="lg" to control the input and wrapper sizing.

Invalid & Disabled

Set aria-invalid to show destructive border styling. Pass disabled to prevent interaction.

Source

Install via CLI: pnpm exec dgadd add ui/search-input.

Highlighted source loads after this disclosure opens. Browse the source repository.