d3-autocomplete
Small autocomplete written using D3
Last updated 4 years ago by emilbay .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install d3-autocomplete 
SYNC missed versions from official npm registry.

d3-autocomplete

Small autocomplete written using D3

PRs welcome!

Install

npm install d3-autocomplete

Usage

var createAutocomplete = require('d3-autocomplete')

var autocomplete = createAutocomplete({placeholder: 'Søg'}, function (query, cb) {
  cb(null, [
    {label: 'Foo', some: 'key'},
    {label: 'Bar', some: 'key'}
  ])
})

autocomplete.on('change', function (data) {
  console.log(data)
})

autocomplete.on('error', function (err) {
  console.error(err)
})

document.body.appendChild(autocomplete.element)

API

createAutocomplete(attrs, queryCallback)

Returns:

{
  element, // The element to add to the DOM
  on(event, listener), // Listen for either `change` or `error` events

  add(suggestion), // Add a suggestion
  delete(suggestion), // Remove a suggestion
  clear(), // Remove all suggestions

  open(), // Open suggestions
  close(), // Close suggestions
  toggle(), // Toggle suggestions

  query([value]) // Set/get query of autocomplete
}

attrs

Type: Object

Various attributes to change on the elements created. See the source

queryCallback(query, callback)

Type: Function

Called when requesting completions for query. Pass back results through callback(err, result)

License

ISC

Current Tags

  • 5.0.1                                ...           latest (4 years ago)

6 Versions

  • 5.0.1                                ...           4 years ago
  • 5.0.0                                ...           4 years ago
  • 4.1.0                                ...           4 years ago
  • 4.0.0                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (2)
Downloads
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 1
Last Month 4
Dependencies (4)
Dev Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |