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
5
Maintainers
84
Versions
72
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@algolia/autocomplete-js

Fast and fully-featured autocomplete JavaScript library.


Version published
Maintainers
84
Created

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.1 (2024-05-14)

Bug Fixes

  • js: allow body scroll when detached mode responsively disabled (#1251) (710f86b), closes #1250

Features

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 14 Feb 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