Once the autocomplete component binds to input via inputSelector
and dropdownSelector
, it then renders autocomplete provided in a render
function. It is called on input focus and change events, and renders a dropdown element with the current search result state:
if input is empty and history entries exist, it renders dropdown with history list,
if input is not empty and it passes minQueryLength
rule, it render dropdown with keywords and products.
Render can be adjusted to the desired framework. Moreover, the library provides helpers for Mustache/Liquid template languages.
Examples
Suppose index.html
is
List of autocomplete
initialization examples:
Liquid
Example below uses fromLiquidTemplate
helper which renders string template. Library provides default autocomplete template via defaultLiquidTemplate
and default css for default template:
The template also can be loaded from a file. The library includes a default template, equivalent to string template in above example:
Mustache Mustache template is rendered similarly as Liquid template in the above example:
Or from a file:
React/Preact
One way to initialize autocomplete in a React app, is to call autocomplete
from the useEffect
on component mount, using default <Autocomplete />
component and styles:
The Preact solution does not differ from React a lot: