Search Input
Terminal-styled search input with / prefix and keyboard event callbacks. Supports controlled and uncontrolled modes.
Installation
dgadd ships in @diffgazer/add on npm: pnpm add -D @diffgazer/add puts it on pnpm exec, and npx @diffgazer/add runs it without the install.
UI components require Tailwind CSS v4. Local copy mode imports src/styles/styles.css; package mode uses @diffgazer/ui CSS from the installed package.
Usage
Examples
Custom
Sizes, invalid, disabled
Keyboard Navigation
API Reference
SearchInput
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.
| Key | Action |
|---|---|
| Escape | Clears the current value when it is non-empty; otherwise calls onEscape when provided. |
| Enter | Calls onEnter when provided. |
| ArrowRight | With 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 keys | Forward through onKeyDown so a parent listbox, combobox, or custom search flow can own navigation. |
With keyboard navigation
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.