Détail du package

suggestions

tristen584.1kISC1.7.1

A typeahead component for inputs

typeahead, autocomplete, component

readme

Suggestions

A typeahead component for inputs

npm version Circle CI

Demo

Usage

Quick start

<script src='suggestions.js'></script>

<script>
  var input = document.querySelector('input');
  var data = ['foo', 'bar', 'baz', 'qux'];
  new Suggestions(input, data);
</script>

Usage with Browserify

var Suggestions = require('suggestions');

var input = document.querySelector('input');
var data = ['foo', 'bar', 'baz', 'qux'];
new Suggestions(input, data);

Suggestions with options

var Suggestions = require('suggestions');

var input = document.querySelector('input');

var data = [{
  name: 'Roy Eldridge',
  year: 1911
}, {
  name: 'Roy Hargrove',
  year: 1969
}, {
  name: 'Tim Hagans',
  year: 1954
}, {
  name: 'Tom Harrell',
  year: 1946
}, {
  name: 'Freddie Hubbard',
  year: 1938
}, {
  name: 'Nicholas Payton',
  year: 1973
}, {
  name: 'Miles Davis',
  year: 1926
}, {
  name: 'Dizzy Gillespie',
  year: 1917
}, {
  name: 'Rex Stewart',
  year: 1907
}];

var typeahead = new Suggestions(input, data, {
  minLength: 3, // Number of characters typed into an input to trigger suggestions.
  limit: 3 //  Max number of results to display. 
});

typeahead.getItemValue = function(item) {
  return item.name
};

input.addEventListener('change', function() {
  console.log(typeahead.selected); // Current selected item.
});

API

Running locally

npm install && npm start

npm start will run a server on port 9966. Visit http://localhost:9966/demo/ to view the example.

Testing

npm run test

Credit

This project is adapted from https://github.com/marcojetson/type-ahead.js

changelog

v1.7.1

  • Only add to window if window exists #42

v1.7.0

  • [feature] Add hideOnBlur option #30

v1.6.0

  • Add renderError method to enable messages with arbitrary text #29

v1.5.0

  • Add wrapper around ul.suggestions #28

v1.4.0

  • [feature] Add custom html rendering function #25

v1.3.4

  • [bug] Enable usage of tab to focus next element after selection #24

v1.3.3

  • [bug] permit special characters #21

v1.3.2

  • [bug] prevent form submission on selecting a result from the list #15
  • [bug] ensure paste events open list #17
  • [bug] use mouseup rather than mousedown for list selection #18

v1.3.1

  • [bug] Fix update method #12

v1.3.0

  • [featurel] filter option #11

v1.2.0

  • [featurel] clear method #10

v1.1.3

  • Passing tests

v1.1.2

  • [bug] Clear container when update is called #9
  • [bug] Export Suggestions as class #8

v1.1.1

  • [bug] Account for mousedown selection of value #7

v1.1.0

  • Adds fuzzy filtering #5.
  • Removed call want bind was already employed #2