Search

A search field is a text input enhanced for finding results. It can be used alone or with a typeahead menu of list items. 

On this page

Import

Default Value Search

Loading preview
Open in Storybook

Loading

Loading preview
Open in Storybook

Props

Search Input Props

NameDescriptionDefault
showSearchButton

If true, shows search button. Otherwise, shows search icon

boolean
true
isOpen

Controlled mode, popup stays open

boolean
-
defaultIsOpen

Popup is open on first load

boolean
-
isOpenOnFocus

If true, popup will open when input receives focus

boolean
true
label

Text that will be used as the visual and accessible label for the component

string
-
getFilteredResults

Custom filter function that takes the search query and returns an array of React elements

((query: string) => (string | number | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal)[])
undefined
onActiveResultChange

Function to be called when the active result changes via keyboard navigation

KeyboardEventHandler<HTMLInputElement>
-
onResultSelect

Function to be called when the result is either clicked or selected via Enter/Return key

((event: KeyboardEvent<HTMLInputElement> | MouseEvent<HTMLLIElement, MouseEvent>, resultId: string) => void)
-
onResultsClose

Function to be called when results are closed

(() => void)
-
action

Specifies the URL where the form data should be sent when submitted. If omitted, form data will be submitted against the current page.

string
-
id*

The id of the input component, used to associate the input with the built-in accessible label and hint

string
-
disabled

@deprecated use aria-disabled instead.

The disabled prop removes the element from the Accessibility Tree and prevents it from receiving focus. This is not recommended.

All DLS components are designed to use the aria-disabled property instead, which will style the component to be disabled, but still allow keyboard focus and screen reader interactivity.

boolean
-
aria-disabled

If true, styles component as disabled and prevents interactivity. Screen reader reads as "dimmed" or "disabled".

Booleanish
-
ref
((instance: HTMLInputElement | null) => void) | RefObject<HTMLInputElement> | null
-
autoComplete

Must be defined when the form control collects user personal data. Attribute value must match the tokens defined in input purposes section

string
-
name

The name attribute of the input field, will default to the id provided

string
-
required

Flag to allow for default validation message to show

boolean
-
type

The type of the input component, defaults to 'text'

HTMLInputTypeAttribute
-
value

Value shown in input (controlled mode)

string
-
onChange

The onChange event handler to attach to the input field (controlled)

ChangeEventHandler<HTMLInputElement>
-
defaultValue

Default value to be used as the search query and shown in input

string
-
aria-describedby

The id of the container of the text describing the input, intended for custom hint text

string
-
inputSlot

@ignore

undefined
-
isVisuallyDisabled

@ignore

undefined
-
statusMessageId

@ignore

undefined
-
childrenPosition

Positions the slot (children) to the left or right of the other content within the container

"start" | "end"
-
status

Default, error, or success state. Will use the value provided by the context when wrapped in a FieldControl component.

FieldControlStatus
-
statusMessage

The status message to be displayed if status is 'success' or 'error'.

string
-
containerRef

A ref to the container element

RefObject<HTMLDivElement> | ((instance: HTMLDivElement | null) => void)
-
containerProps

Props to be spread onto the parent div container

Omit<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">
-
onClearSearch

Function called when clear search term button is clicked

MouseEventHandler<HTMLButtonElement>
-
onSearch

Function called when search button is clicked and when form is submitted

FormEventHandler<HTMLFormElement>
-
isLoading

If true, show loading state for search

boolean
-
searchButtonProps

Props to be spread onto search button

IconButtonOtherProps
-
clearButtonProps

Props to be spread onto clear search query button

IconButtonOtherProps
-
hint

Hint text to use inbuilt hint instead of a custom label

string
-
isHintVisuallyHidden

If true, visually hides the hint text (it will still be accessible to screen readers)

boolean
-
tooltip

The slot for the tooltip

ReactElement<({ id, placement: placementProp, disableHover, isOpen: openProp, defaultIsOpen, onIsOpenChange, children, shouldCreatePortal, }: TooltipProps) => Element, string | JSXElementConstructor<any>>
-
reactlytics
ReactlyticsProp
-
labelOverrides

Overrides for labels that have been defaulted in the component.

SearchLabelOverrides
-

Search Results Props

NameDescriptionDefault
id

ID for each li element

string
-
onFocus

Function called when li element receives focus

FocusEventHandler<HTMLLIElement>
-
onMouseDown

Function called on mouse down event on li element

MouseEventHandler<HTMLLIElement>
-
onMouseEnter

Function called on mouse enter event on li element to set the aria-selected attribute

MouseEventHandler<HTMLLIElement>
-
selectedResult

Object that contains the id and index of the selected li element

{ id: string | null; index: number; }
-

Questions?

Connect with the DLS Team on Slack or by email.

Resources

Check out additional resources.