Socket
Socket
Sign inDemoInstall

@trevoreyre/autocomplete

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@trevoreyre/autocomplete

Simple autocomplete component in vanilla JS and Vue


Version published
Weekly downloads
776
decreased by-14.16%
Maintainers
1
Weekly downloads
 
Created
Source

@trevoreyre/autocomplete

The core package provides the base functionality of the autocomplete component. It provides an instance to track the current state, and event handlers to respond to user input. It doesn't actually render anything to the DOM, so that it can remain flexible and be used in multiple platforms.

The best way to learn how to use the core package is to take a look at the source code of other components that provide a rendering layer on top of it, like the JavaScript component and the Vue component

Demo

Take a look at the documentation page, and the Codepen examples.

Installation

Install the component from npm.

npm install --save @trevoreyre/autocomplete

Or using yarn.

yarn add @trevoreyre/autocomplete

You can also use the browser bundle in a script tag.

<script src="https://unpkg.com/@trevoreyre/autocomplete"></script>

Usage

The core package provides a class instance to handle the internal state of the autocomplete component. The component can be tweaked using a number of constructor arguments.

const autocomplete = new Autocomplete(options)

Arguments

ArgumentTypeDescription
searchFunction (required)The search function to be executed on user input. Can be a synchronous function or a Promise.
autoSelectBooleanControls whether first result should be highlighted after input
setValueFunctionSets the value of the calling component's input element
setAttributeFunctionSets attributes on the calling component's input element
onUpdateFunctionFired when the results list is updated. Receives results (Array), and selectedIndex (Number) as arguments.
onSubmitFunctionFired when user submits result. Receives result as argument.
onShowFunctionFired when the results list is shown
onHideFunctionFired when the results list is hidden
onLoadingFunctionFired if search is a Promise and hasn't resolved yet
onLoadedFunctionFired after asynchronous search function resolves
submitOnEnterBooleanIf true, immediately call onSubmit on result when pressing Enter. Default: false

Event handlers

The core package provides a number of event handlers that can be wired up in the calling component.

NameDescription
handleInputHandles the input element's input event
handleKeyDownHandles the input element's keydown event
handleBlurHandles the input element's blur event
handleResultMouseDownHandles the ul element's mousedown event
handleResultClickHandles the ul element's click event

Methods

NameDescription
destroyRemoves all event listeners and object references that were set during initialization.

Keywords

FAQs

Package last updated on 16 Jan 2023

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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc