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

PropTypeDescriptionDefault
aria-activedescendant?stringIdentifies 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?stringIdentifies the element(s) that the text input controls._
aria-expanded?booleanIndicates 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?stringIndicates if autocomplete is enabled for the input field._
autoCorrect?'on' | 'off'Indicates if auto-correction is turned on for the input._
autoFocus?booleanAutomatically sets focus on the input field when it appears_
defaultValue?string | number | readonly string[] | undefinedThe initial value of the text input._
disabled?booleanWhen true, the input becomes uneditable, makes it read-only, and blocks interaction.false
inputMode?"none" | "text" | "tel" | "url" | "email" | "numeric" | "decimal" | "search" | undefinedIt specifies the type of virtual keyboard to display, helping users enter the correct type of data more easily._
name?string | undefinedIdentifier for the input, used in form submissions._
onBlur?functionA function that executes when the input loses focus._
onChange?functionA function that executes when the input's value changes._
onFocus?functionA function that triggered when the input receives focus._
onKeyDown?functionA function that called when a key is pressed while the input is focused._
onPaste?functionA function that executes when content is pasted into the input._
pattern?stringRegular expression pattern the input's value must match for validation._
placeholder?stringPlaceholder text displayed when the input is empty._
role?stringARIA role for the input._
spellCheck?booleanIndicates if the input value should be checked for spelling errors._
value?string | number | readonly string[] | undefinedDefines 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.