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

PropDefaultDescription
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?falseboolean
When true, the input becomes uneditable, makes it read-only, and blocks interaction.
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 PartsDescription
rootThe container that wraps the search input.
adornmentStartAn element (like an icon or button) that appears at the start of the input field.
adornmentEndAn element (like an icon or button) that appears at the end of the input field.