3.0.2 • Published 29 days ago

@trevoreyre/autocomplete v3.0.2

Weekly downloads
1,629
License
MIT
Repository
github
Last release
29 days ago

@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.
3.0.2

29 days ago

3.0.1

1 month ago

3.0.0

1 month ago

2.4.1

1 year ago

2.4.0

1 year ago

2.3.0

2 years ago

2.2.0

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.4

4 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.22

5 years ago

0.0.21

5 years ago

0.0.20

5 years ago

0.0.19

5 years ago

0.0.18

5 years ago

0.0.17

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago