You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

@algolia/autocomplete-js

Package Overview
Dependencies
Maintainers
87
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@algolia/autocomplete-js

Fast and fully-featured autocomplete JavaScript library.


Version published
Weekly downloads
112K
increased by0.32%
Maintainers
87
Created
Weekly downloads
 

Package description

What is @algolia/autocomplete-js?

@algolia/autocomplete-js is a JavaScript library that provides a highly customizable autocomplete experience. It is designed to be flexible and easy to integrate with various data sources, including Algolia's search API. The package allows developers to create powerful and responsive autocomplete interfaces with minimal effort.

What are @algolia/autocomplete-js's main functionalities?

Basic Autocomplete Setup

This code sets up a basic autocomplete interface with a static list of items. The `autocomplete` function initializes the autocomplete widget, and the `getSources` method defines the data sources for the autocomplete suggestions.

```javascript
import { autocomplete } from '@algolia/autocomplete-js';

autocomplete({
  container: '#autocomplete',
  getSources() {
    return [
      {
        sourceId: 'example-source',
        getItems() {
          return [
            { label: 'Item 1' },
            { label: 'Item 2' },
            { label: 'Item 3' }
          ];
        },
        templates: {
          item({ item }) {
            return item.label;
          }
        }
      }
    ];
  }
});
```

Using Algolia Search API

This example demonstrates how to integrate the autocomplete widget with Algolia's search API. The `getItems` method performs a search query using Algolia's client and returns the search results as autocomplete suggestions.

```javascript
import { autocomplete } from '@algolia/autocomplete-js';
import algoliasearch from 'algoliasearch/lite';

const searchClient = algoliasearch('YourApplicationID', 'YourSearchOnlyAPIKey');

autocomplete({
  container: '#autocomplete',
  getSources() {
    return [
      {
        sourceId: 'products',
        getItems({ query }) {
          return searchClient
            .initIndex('products')
            .search(query)
            .then(({ hits }) => hits);
        },
        templates: {
          item({ item }) {
            return item.name;
          }
        }
      }
    ];
  }
});
```

Customizing Autocomplete Templates

This code sample shows how to customize the templates used for rendering autocomplete suggestions. The `item` template is modified to include both a label and a description for each suggestion.

```javascript
import { autocomplete } from '@algolia/autocomplete-js';

autocomplete({
  container: '#autocomplete',
  getSources() {
    return [
      {
        sourceId: 'example-source',
        getItems() {
          return [
            { label: 'Item 1', description: 'Description 1' },
            { label: 'Item 2', description: 'Description 2' },
            { label: 'Item 3', description: 'Description 3' }
          ];
        },
        templates: {
          item({ item }) {
            return `<div>
                      <strong>${item.label}</strong>
                      <p>${item.description}</p>
                    </div>`;
          }
        }
      }
    ];
  }
});
```

Other packages similar to @algolia/autocomplete-js

Changelog

Source

1.17.4 (2024-07-11)

Bug Fixes

  • deps: update search-insights and instantsearch dependencies (#1268) (ebcc557)

Readme

Source

@algolia/autocomplete-js

The autocomplete-js package is an agnostic virtual DOM renderer. You can use it in JavaScript, Preact, React, or Vue projects.

Installation

yarn add @algolia/autocomplete-js
# or
npm install @algolia/autocomplete-js

Documentation

See Documentation.

FAQs

Package last updated on 11 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc