SearchInput
The search input is created using <TextInput /> comes with various sizes and variants and is wrapped using <Field /> component.
It also includes accessibility features like a clear button and escape key for easy clearing. For options like error message and disabling, see Field to get more details.
Quick Start
- Installation
npm install @adaptavant/eds-core- Import
import { SearchInput } from '@adaptavant/eds-core';
Size
Customise the size of the SearchInput via the size prop on Field.
{/* standard */}
<Field labelVisibility="hidden" size="standard">
<SearchInput placeholder="Placeholder" />
</Field>
{/* large */}
<Field labelVisibility="hidden" size="large">
<SearchInput placeholder="Placeholder" />
</Field>
Variant
Customise the appearance of the SearchInput via the variant prop.
{/* standard */}
<Field labelVisibility="hidden">
<SearchInput placeholder="Placeholder" variant="standard" />
</Field>
{/* subtle */}
<Field labelVisibility="hidden">
<SearchInput placeholder="Placeholder" variant="subtle" />
</Field>
Controlled
To control a SearchInput provide a value, as well as an onChange function to set the new value whenever it is updated.
const [value, setValue] = React.useState('')
const handleChange = (event) => setValue(event.target.value)
return (
<Field>
<SearchInput value={value} onChange={handleChange} />
</Field>
<Text>The current value is: {value}</Text>
);
Additionally, if you want a clear button provide an onClear function to clear the value.
const [value, setValue] = React.useState('')
const handleChange = (event) => setValue(event.target.value)
const handleClear = () => setValue('')
return (
<Field>
<SearchInput value={value} onChange={handleChange} onClear={handleClear} />
</Field>
<Text>The current value is: {value}</Text>
);
Uncontrolled
When using formData from a request object to populate form data, you can use an uncontrolled SearchInput component. In this case, you don't need to provide any state or update functions. If you're using a form library like react-hook-form that uses an imperative API to retrieve the value of a form control, we forward the ref to the underlying <input>element. Here's an example:
const ref = useRef(null);
return (
<Field>
<SearchInput ref={ref} placeholder="Placeholder" />
</Field>
);
API Reference
SearchInput
| Prop | Type | Description | Default |
|---|---|---|---|
aria-activedescendant? | string | Identifies the currently active element when DOM focus is on the text input. | _ |
aria-autocomplete? | "none" | "inline" | "list" | "both" | Indicates whether inputting text field can show suggested values and how those suggestions appear. | _ |
aria-controls? | string | Identifies the element(s) that the text input controls. | _ |
aria-expanded? | boolean | Indicates whether the element, or another grouping element it controls, is currently expanded or collapsed. | _ |
aria-haspopup? | boolean [ "false" | "true" | "menu" | "listbox" | "tree" | "grid" | "dialog" ] | Indicates the availability of a popup related to the text input. | _ |
autoComplete? | string | Indicates if autocomplete is enabled for the input field. | _ |
autoCorrect? | 'on' | 'off' | Indicates if auto-correction is turned on for the input. | _ |
autoFocus? | boolean | Automatically sets focus on the input field when it appears | _ |
defaultValue? | string | number | readonly string[] | undefined | The initial value of the text input. | _ |
disabled? | boolean | When true, the input becomes uneditable, makes it read-only, and blocks interaction. | false |
inputMode? | "none" | "text" | "tel" | "url" | "email" | "numeric" | "decimal" | "search" | undefined | It specifies the type of virtual keyboard to display, helping users enter the correct type of data more easily. | _ |
name? | string | undefined | Identifier for the input, used in form submissions. | _ |
onBlur? | function | A function that executes when the input loses focus. | _ |
onChange? | function | A function that executes when the input's value changes. | _ |
onFocus? | function | A function that triggered when the input receives focus. | _ |
onKeyDown? | function | A function that called when a key is pressed while the input is focused. | _ |
onPaste? | function | A function that executes when content is pasted into the input. | _ |
pattern? | string | Regular expression pattern the input's value must match for validation. | _ |
placeholder? | string | Placeholder text displayed when the input is empty. | _ |
role? | string | ARIA role for the input. | _ |
spellCheck? | boolean | Indicates if the input value should be checked for spelling errors. | _ |
value? | string | number | readonly string[] | undefined | Defines the default or current value of the input field. | _ |
focusContainerRef? | React.Ref<HTMLDivElement> | Reference to the wrapper FocusContainer element. | _ |
Style API
Our design system components include style props that allow you to easily customize different parts of each component to match your design needs.
Please refer to the Style API documentation for more insights.
SearchInput parts
return (
<>
<Field labelVisibility="hidden" size="standard">
<SearchInput
className="bg-caution-secondary"
classNames={{
adornmentStart: 'bg-positive p-2',
adornmentEnd: 'bg-critical w-4',
}}
placeholder="Placeholder"
/>
{/* adornmentStart is used to display the search icon, and adornmentEnd is used to clear the input, both are handled internally. */}
</Field>
</>
);
| Stylable Parts | Description |
|---|---|
root | The container that wraps the search input. |
adornmentStart | An element (like an icon or button) that appears at the start of the input field. |
adornmentEnd | An element (like an icon or button) that appears at the end of the input field. |