This widget is and is subject to change in minor versions.
You are viewing the documentation for InstantSearch.js v4.
To upgrade from v3, see the migration guide.
Looking for the v3 version of this page?
View the v3 docs.
Signature
Import
About this widget
Theautocomplete widget 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
Options
The CSS Selector or
HTMLElement to insert the widget into.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 requesttemplates: the templates to use for the index
JavaScript
Configures the query suggestions feature.
indexName: the name of the index to query for suggestionsgetURL: update the url to send the search requesttemplates: the templates to use for the suggestions
JavaScript
Additional search parameters to send with the search request for every index.
JavaScript
The CSS classes you can override:
root. The widget’s root element.list. The list of results.item. The list of items.
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
Templates
You can customize parts of a widget’s UI using the Templates API. Each template includes anhtml function,
which you can use as a tagged template.
This function safely renders templates as HTML strings and works directly in the browser—no build step required.
For details, see Templating your UI.
The
html function is available in InstantSearch.js version 4.46.0 or later.Use the
template option to customize how the panel is rendered.
This is useful when implementing layouts with multiple rows or columns.The template receives an object 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 template to use for the header, before the list of items for that index.
JavaScript
The template to use for each item that is returned by the search query on that index.
JavaScript