This widget is and is subject to change in minor versions.
This is the React InstantSearch v7 documentation.
If you’re upgrading from v6, see the upgrade guide.
If you were using React InstantSearch Hooks,
this v7 documentation applies—just check for necessary changes.
To continue using v6, you can find the archived documentation.
Signature
Import
JavaScript
About this widget
<Autocomplete> is one of the most common widgets in a search UI.
With this widget, users can get search results as they type their query.
This widget includes a “showSuggestions” feature that displays query suggestions from a separate index.
Examples
JavaScript
Props
An array of objects that define the indices to query and how to display the results.
indexName: the name of the index to querygetQuery: preprocess the query before it is sent for searchgetUrl: update the url to send the search requestsearchParameters: additional search parameters to send with the search requestheaderComponent: component to render for the header of the indexitemComponent: component to render for each result from a query
JavaScript
Configures the query suggestions feature.
indexName: the name of the index to query for suggestionsgetURL: update the url to send the search requestheaderComponent: component to render for the header of the indexitemComponent: component to render for each suggestion
JavaScript
Additional search parameters to send with the search request for every index.
JavaScript
A function that is called when the user selects an item. If not provided, the default implementation:
- navigates to the URL of an item if the index configuration defines
getURL(); - or navigates to the URL of the search page if autocomplete is not in a search page and
getSearchPageURL()is defined; - or otherwise refines the query
JavaScript
A function that returns the URL of the search page for a given search state.
JavaScript
Use the component to customize how the panel is rendered.
This is useful when implementing layouts with multiple rows or columns.The component receives a prop containing:
elements: a key-value dictionary of indices to render. These include regular index names, and special elements likerecentandsuggestions, if applicable.indices: an array containing the data for each index.
JavaScript
The CSS classes you can override
and pass to the widget’s elements.
It’s useful to style widgets with class-based CSS frameworks like Bootstrap
or Tailwind CSS.
root. The widget’s root element.list. The list of results.item. The list of items.
JavaScript