<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-5HGSQD2L" height="0" width="0" style="display:none;visibility:hidden" title="GTM"></iframe>

Search Input

Input field for search queries.

Use Search Input...

  • For page search query.

Don't use Search Input...

The preview has been updated.

Managing state

As is the case with most form elements, folks often want to "control" this component. Controlling a component means that you take ownership over its state rather than letting the browser manage the state for you. When you control a component,Β youΒ own the source of truth for the UI. This means that you don't need to query the DOM in order to determine the current value of the element. So, when it comes time to use the value of the element somewhere else (e.g. submitting the selection to a back-end service) you can trust your stored value.

The preview has been updated.

Accessibility

Provide assistive devices with information on what the input field does. You can either:

  • Use an aria-label attribute with a localized value.
  • Wrap the Search Input into a FormField with a FormLabel component with the visuallyHidden prop. Refer to Form

Provide assistive devices with information on what the buttons do for the Search and Clear icon buttons that are simply icons and have no visible text. For react users, the following props are required: accessibleTextForClearButton and accessibleTextForSearchButton.

Implementation

Avoid placing a Search Input inside an element that is a table cell or has CSS display: table-cell. This configuration may result in the Search Input being rendered more narrowly than its actual minimum width. Use Grid to constrain it instead.

Anatomy

For local search instances, consider including an on-page label to:

  • Help make the function of the searchbar more evident.
  • Provide additional context to the interaction.

If an on-page label is included, consider using the searchbar placeholder text to provide additional helpful instructions.

Content accessibility

AA (required)

AAA (advised)

If search instance includes an on-page label:

Content identity (editorial)

Ensure all content adheres to our global copy style guide standards.

Content usability

  • Make sure wording is specific, instructional and contextual.
  • Use <verb> + <noun> sentence structure for label and button text
    • See Language section for more information.

Representative examples:

The preview has been updated.

Language

Label/placeholder text

  • Verb should always be β€˜search’.
  • Noun phrase should be specific to the search context (global or local).

Representative examples:

Verb

Noun

Search

t shirts

Search

your order history

Search

help articles

Search

logo ideas

Search

gallery templates

Localization

  • Use plain English to help ensure source language is easy and efficient to translate.
  • Remember to allow for text expansions for other languages - roughly 35%.

SEO

All internal searches made through the global site search bar are non-indexable which means they are not available for Google to use in its search results. As long as that rule remains in place any change on how internal searches are made and/or results are displayed won't have any effect on our SEO.

Props

SearchInput
This component is implemented using the <input /> as the root element. You can utilize the native attributes supported by <input /> tag. The ref is directly assigned to the root element, allowing you to access and manipulate it as needed.
See core props for additional props that can be applied to this component.
proptyperequireddescriptiondefault
skin"standard" | "error" | nullfalse
The visual variant. Note that error is implied if the SearchInput is used inside of a FormInput that also contains a FormError. Available options: 'standard', 'error'
null
onClear((...args: any[]) => any) | nullfalse
The click handler for the clear button
null
onSearchSubmit((...args: any[]) => any) | nullfalse
The click handler for the search button
null
accessibleTextForClearButtonstringtrue
-
null
accessibleTextForSearchButtonstringtrue
-
null

Related