Search input
A single-line search field with a clear affordance
Deployments
- api-gatewayfra1 · edge
- billing-workeriad1 · queue
- docs-sitesfo1 · static
- postgres-primaryiad1 · database
- search-indexfra1 · worker
- web-consolesfo1 · frontend
Installation
npx shadcn@latest add @sudokw/components-search-inputimport { SearchInput } from "@gpuixui/components";Usage
import { SearchInput } from "@gpuixui/components/search-input";
import { Text } from "@gpuixui/primitives";
import { useState } from "react";
export const FileFilter = () => {
const [query, setQuery] = useState("");
const [last, setLast] = useState("none");
return (
<>
<SearchInput
aria-label="Filter files"
placeholder="Filter files…"
value={query}
onValueChange={setQuery}
onSubmit={setLast}
onClear={() => setQuery("")}
/>
<Text role="caption">Last submitted: {last}</Text>
</>
);
};Composition
SearchInput
├── leading mark
├── input
└── clear controlAPI reference
| Prop | Type | Default | Consequence |
|---|---|---|---|
value | string | none | the controlled text; omit it to let the field keep its own |
defaultValue | string | "" | the initial text in uncontrolled mode |
onValueChange | (value: string) => void | none | every edit, including the clear and Escape paths |
onChange | host change event | none | the raw host payload, called before the value is applied |
onSubmit | (value: string) => void | none | Enter, with the current text |
onClear | () => void | none | the clear control or Escape, only when the field held text |
placeholder | string | "Search…" | the hint the field paints — and announces — while the value is empty |
disabled | boolean | false | readOnly plus the half-opacity paint; no ring, no tab stop, and an inert clear target |
className | string | none | joined after the recipe, so it wins conflicts |
style | StateStyle<SearchInputState> | none | resolved against { disabled, focused } and merged last on the field surface |
testId | string | "search-input" | the input's locator; the painted hint is ${testId}-hint |
label / description | string | none | the field's accessible name, and the help it announces |
invalid | boolean | false | the destructive edge a failed search paints |
required | boolean | false | the field is required by the form around it |
readOnly / autoFocus | boolean | false | uneditable, or focused on mount |
size / fullWidth / tabIndex | "sm" | "md" | "lg" · boolean · number | "md" · false · the field's place | height and padding from density, the full width, and the tab order |
ref / aria-id / onLayout | the addressed element | none | the inner <input>: focus it, measure it, name it for automation |
onClick / onKeyDown / onKeyUp / onFocus / onBlur | host handlers | none | composed with the field's own; yours runs first |
Keyboard
- Escape
- clears the field
- EnterSpace
- clears through the clear target
Enter in the field submits through `onSubmit`.
read from search-input.tsx
Edit this page on GitHubapps/docs/content/docs/components/search-input.mdx