Skip to main content
This example builds on the autocomplete widget guide. It creates a federated autocomplete experience with recent searches and Query Suggestions on the left, and product previews on the right.
This widget is and is subject to change in minor versions.
Federated autocomplete with recent searches and Query Suggestions on the left and product previews on the right (desktop)

Open CodeSandbox

Run and edit the federated autocomplete example in CodeSandbox.

Explore source code

Browse the source code for the federated autocomplete example on GitHub.
The example has three states. Each one arranges the same two columns differently: The sections below build each piece, then combine them in a single panel template. The panel template arranges the sources into two columns, and each source brings its own header and item templates:
JavaScript
Add CSS for the columns, product rows, and state-specific elements. The example style sheet includes classes for:
  • Two-column grids
  • Product rows
  • Quick-access cards
  • “See all” and no-results states

Add a quick-access panel

You can show promotional cards or shortcuts when the query is empty. Define them as static data and render them in the panel template. When users type a query, show product previews instead:
JavaScript
For dynamic cards, return custom data from an Algolia rule. In the panel template, read the data from results.userData for the products index instead of using a static array.

Add a category suggestion

To show a category suggestion in the left column, find the products index and read the top product’s categories from results.hits[0] in the panel template. Guard against a missing or empty categories attribute, then render the category after the suggestions:
JavaScript
The index source has no footer template. To show a See all link with the total number of matching results, read the products index’s results.nbHits in the panel template and render the link after the product previews:
JavaScript

Show the no-results state

When a result source has no items, the widget doesn’t render its item template. Use the source’s noResults template to show a message such as “No products found”, as shown in the main example.

Combine the empty and typing states

The final panel template combines two states:
  • For an empty query, show recent and popular searches in the left column and quick-access cards in the right column.
  • After users enter a query, show Query Suggestions and a category in the left column and product previews in the right column.
To switch between the states:
  • Remove the header template from showQuerySuggestions.
  • Render the suggestions heading in the panel template. Use “Popular searches” for an empty query and “Suggestions” for a non-empty query.
  • Show the heading only when the Query Suggestions source has results.
For the assembled panel template, see src/app.js.

See also

Last modified on July 21, 2026