Prefer using the Autocomplete widget from InstantSearch instead of the standalone Autocomplete library.
It integrates more closely with your search experience.
For more information,
see the API reference for InstantSearch.js or
React InstantSearch.
Open CodeSandbox
Run and edit the Basic configuration options example in CodeSandbox.
- The container you want your autocomplete to go in.
- The sources from which to get the items to display (see more in Sources).
container option refers to where to inject the autocomplete in your HTML.
It can be a CSS selector
or an Element.
Make sure to provide a container (like a div), not an input.
Autocomplete generates a fully accessible search box for you.
HTML
- Use
placeholderto define the text that appears in the input before users type anything. - Use
autoFocusto focus on the search box on page load, andopenOnFocusto display items as soon as a user selects the autocomplete, even without typing. - Use the
onStateChangelifecycle hook to run code whenever the state changes. - Use
debug: trueto keep the autocomplete panel open even when the blur event occurs (see Debugging).