useSearchField

Provides the behavior and accessibility implementation for a search field.

Example
SearchField.tsx
SearchField.css
TextField.css
Form.css
import {SearchField} from './SearchField';

<SearchField label="Search" onSubmit={text => alert(text)} />

API

Shows a search field component with labels pointing to its parts, including the label, input, and clear button elements.ValueLabelInputLabelClear button
<SearchField>
  <Label />
  <Input />
  <Button />
  <Text slot="description" />
  <FieldError />
</SearchField>
useSearchFieldState(props: ): useSearchField( props: , state: , inputRef: <HTMLInputElementnull> ):

SearchFieldState

Properties

NameType

Methods

setValue(value: string): void
Sets the value of the search field.

AriaSearchFieldProps

NameTypeDefault
enterKeyHint'enter''done''go''next''previous''search''send'Default:

An enumerated attribute that defines what action label or icon to preset for the enter key on virtual keyboards. See MDN.

type'text''search''url''tel''email''password'string{}Default: 'search'

The type of input to render. See MDN.

isDisabledbooleanDefault:

Whether the input is disabled.

isReadOnlybooleanDefault:

Whether the input can be selected but not changed by the user.

placeholderstringDefault:

Temporary text that occupies the text input when it is empty.

inputMode'none''text''tel''url''email''numeric''decimal''search'Default:

Hints at the type of data that might be entered by the user while editing the element or its contents. See MDN.

autoCorrectstringDefault:

An attribute that takes as its value a space-separated string that describes what, if any, type of autocomplete functionality the input should provide. See MDN.

spellCheckstringDefault:

An enumerated attribute that defines whether the element may be checked for spelling errors. See MDN.

valuestringDefault:

The current value (controlled).

defaultValuestringDefault:

The default value (uncontrolled).

onChange(value: T) => voidDefault:

Handler that is called when the value changes.

SearchFieldAria

NameType
labelPropsLabelHTMLAttributes<HTMLLabelElement>

Props for the text field's visible label element (if any).

inputPropsInputHTMLAttributes<HTMLInputElement>

Props for the input element.

clearButtonProps

Props for the clear button.

descriptionPropsDOMAttributes

Props for the searchfield's description element, if any.

errorMessagePropsDOMAttributes

Props for the searchfield's error message element, if any.

validationDetailsValidityState

The native validation details for the input.