Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/emilbayes/d3-autocomplete
Small autocomplete written using D3
https://github.com/emilbayes/d3-autocomplete
Last synced: 17 days ago
JSON representation
Small autocomplete written using D3
- Host: GitHub
- URL: https://github.com/emilbayes/d3-autocomplete
- Owner: emilbayes
- License: isc
- Created: 2016-08-05T09:40:24.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-09-08T05:34:32.000Z (about 8 years ago)
- Last Synced: 2024-10-17T16:31:21.293Z (27 days ago)
- Language: JavaScript
- Homepage:
- Size: 12.7 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# `d3-autocomplete`
> Small autocomplete written using D3
**PRs welcome!**
## Install
```sh
npm install d3-autocomplete
```## Usage
```js
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:
```js
{
element, // The element to add to the DOM
on(event, listener), // Listen for either `change` or `error` eventsadd(suggestion), // Add a suggestion
delete(suggestion), // Remove a suggestion
clear(), // Remove all suggestionsopen(), // Open suggestions
close(), // Close suggestions
toggle(), // Toggle suggestionsquery([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](LICENSE.md)