Autocompletes allow users to enter any combination of letters, numbers, or symbols of their choosing (unless otherwise restricted), and receive one or more suggested matches in a list below the input.
Autocomplete component is a parent component that adds autocomplete functionality to a
Screenreader-specific label for the Clear search
Must contain a
Additional classes to be added to the root element. Useful for adding utility classes.
When set to
Text rendered on the page if
Removes the Clear search button when set to
Used to focus child
A unique id to be passed to the child
Customize the default status messages announced to screenreader users via aria-live when autocomplete results are populated. Read more on downshift docs.
Access a reference to the child
Used to determine the string value for the selected item (which is used to compute the
Array of objects used to populate the suggestion list that appears below the input as users type. This array of objects is intended for an async data callback, and should conform to the prescribed shape to avoid errors.
Adds a heading to the top of the autocomplete list. This can be used to convey to the user that they're required to select an option from the autocomplete list.
Can be called when the
Message users will see when the
Message users will see when the
Called when the user selects an item and the selected item has changed. Called with the item that was selected and the new state. Read more on downshift docs.
Called when the child
|Unique identifier for this item|
|Displayed value of the item. May alternatively provide a |
|Custom React node as an alternative to a string-only |
|Additional classes to be added to the root element. Useful for adding utility classes.|
|Whether this item should be counted as one of the results for the purpose of announcing the result count to screen readers|
When to use
- If you are returning results from a known domain like a database of zip codes or a taxonomy of keywords
- If you have a list of options that would cause a dropdown to be unusually long
When to consider alternatives
- When users are choosing from a specific set of options. Consider checkboxes, radio buttons, or a dropdown in these cases.
<Autocomplete>makes use of the
<Downshift>component, maintained by Paypal: Downshift docs on Github. The above documented props are only those directly exposed by the
<Autocomplete>component, but you can pass props specific to
<Downshift>here as well, e.g. you can set the
inputValueprop if you'd like to provide an initial value to the component or control the input more directly.
- We continue to use the ARIA 1.0 Combobox With List Autocomplete pattern. This decision was made ensures good compatibility with assistive devices (JAWS, NVDA, VoiceOver). This was done because the ARIA 1.1 markup pattern triggers a different behavior on containers with a role="combobox" attribute.
- Don't use placeholder text in autocomplete fields. Try to write a descriptive label that identifies what the user is searching for. People who have cognitive or visual disabilities have additional problems with placeholder text.
- The length of the text field provides a hint to users as to how much text to write. Do not ask users to write paragraphs of text in this component; use a
<Autocomplete>component has taken special care to ensure accessibility for screenreader devices. It announces the number of results based on
itemsmatches with the
inputValuestring. The component also reads out the name of each list item when users arrow up or down.
<Autocomplete>allows developers to add hint text in the
<label>element. This hint
<span>is added to the markup by passing a
<Autocomplete>has a button (styled visually as a link) to clear the search, and refocus the
<input>element. This resets the local state
null, and will re-read the label and screenreader hint text.
<Autocomplete>has a new Boolean prop called
focusTrigger. Adding this prop will set keyboard focus on the internal
<Textfield>. Focus is set immediately when the
componentDidMount()lifecycle method fires.
- In most cases, this isn't needed. It's useful when components are added dynamically, after the application has been rendered. All major screen readers (JAWS, NVDA, VoiceOver) have been tested with this feature, and announce the new input correctly.
- Instances that contain the
focusTriggerprop may fire Downshift's onInputValueChange method, causing the
inputValueto be set back to an empty string. In these cases, you may want to access Downshift's state reducer and manage your component's local state for
The following Sass variables can be overridden to customize Autocomplete components: