autocomplete-js
package includes everything you need to render a search experience and bind it to your framework.
Use the autocomplete-core
package to build a custom UI that differs from the autocomplete-js
output.
You might not need a custom renderer.
Building a custom renderer is an advanced pattern that uses the
autocomplete-core
package to fully control the rendered experience.
Don’t use it unless you’ve reached limitations with autocomplete-js
and its templating capabilities.Import the package
Begin by importingcreateAutocomplete
from the core package and getAlgoliaResults
from the Algolia preset.
The preset function autocomplete-preset-algolia
retrieves items from an Algolia index.
JavaScript
Initialize Autocomplete
The Autocomplete entry point is thecreateAutocomplete
function, which returns the methods to create the search experience.
JavaScript
- Use a React state for the Autocomplete component to re-render when the Autocomplete state changes.
- Listen to all Autocomplete state changes to synchronize them with the React state.
- This example uses an Algolia index as a source.
autocomplete
variable in your React components.
Use prop getters
Prop getters are methods that return props to use in your components. These props contain accessibility features, event handlers, and so on. They help create a complete experience without exposing their underlying technical elements. The following snippet shows how to use thegetRootProps()
,
getInputProps()
,
getPanelProps()
,
getListProps()
,
and getItemProps()
prop getters in the appropriate elements.
JSX

Improve input accessibility
To improve theinput
control, wrap it in a form
and apply the form props given by Autocomplete:
JSX
getFormProps
prop getter handles submit and reset events.
It also respectively blurs and focuses the input when these events happen.
Pass the inputElement
when calling getFormProps
to use these features.
Add a label that represents the input and use the getLabelProps
prop getter:
JSX
JSX
Check network status
Displaying UI hints when the network is unstable helps users understand why results aren’t updating in real-time. Examine thestatus
to determine this:
JSX
.aa-Panel--stalled
CSS class that lowers items’ opacity to show that search is temporarily stuck or unavailable.

Mirror a native mobile experience
Native platforms offer better primitives for mobile search experiences. Autocomplete helps provide these capabilities so that the web mobile experience is closer to the native mobile experience. A common feature in mobile native experiences is to close the virtual keyboard when users start scrolling. By automatically hiding the keyboard, you make it simpler for users to discover search results. The panel closes when users tap outside it. ThegetEnvironmentProps
method returns event handlers that let you create this experience:
JSX