Install the plugin
Import the plugin into your project
JavaScript
autocomplete-theme-classic.
JavaScript
script element:
HTML
HTML
Initialize the plugin with initialTags
The plugin lets you pass initialTags for Autocomplete.
Use it when deriving tags from an existing state, such as the route or filter status.
For example, if the URL reflects the current filter state,
you can initialize the plugin with them when the page loads before the Autocomplete instance starts.
JavaScript
Modify tags
By default, the plugin populates a source with the current tags. Users can navigate through them as with any other source and delete them on click or selection. You can customize the source withtransformSource.
If you want to display tags manually,
for example, with the render
function or in the search box, you can prevent the plugin from returning a source.
The plugin exposes an API on the Context to let you access tags.
Returned tags expose a
remove function for removing individual tags.addTags and a setTags function on the context to update the list of tags.
JavaScript
Parameters
A set of initial tags to pass to the plugin.You can use this to pass initial refinements (for example, from local state)
without triggering the Autocomplete lifecycle.
TypeScript
A function to specify what sources the plugin should subscribe to.
The plugin adds a tag when selecting an item from these sources.
sourceId: thesourceIdof the source to subscribe to.getTag: a function to return a tag from the selected items.
JavaScript
Type definition
Example
TypeScript
Returns
data
TypeScript
Adds tags to the list.The only required property is a
label.
You can pass any other property you want, except for remove, which is reserved.JavaScript