项目作者: elcobvg

项目描述 :
A lightweight typeahead / autocomplete component made with Svelte.js
高级语言: HTML
项目地址: git://github.com/elcobvg/svelte-autocomplete.git
创建时间: 2018-07-13T04:59:46Z
项目社区:https://github.com/elcobvg/svelte-autocomplete

开源协议:MIT License

下载


svelte-autocomplete

Lightweight typeahead / autocomplete component made with Svelte.js

  • no dependencies
  • can handle asynchronous data
  • use plain lists or key / value pairs

Try the demo at http://svelte-autocomplete.surge.sh/

Install

npm install svelte-autocomplete

Usage

Import the component directly in your Svelte project.

  1. import AutoComplete from 'svelte-autocomplete'
  2. export default {
  3. components: {
  4. AutoComplete,
  5. ...
  6. }
  7. }

And then use it like so:

  1. <AutoComplete class="input" name="fruits" items="{fruits}" minChar="1" ></AutoComplete>
  2. <AutoComplete name="countries" items="{countries}" isAsync on:input="loadApiData(event)">
  3. <div class="notification">Loading data from API...</div>
  4. </AutoComplete>

Options

Prop Type Default Description
name String - Form input name
class String - Additional styles for input element
items Array - Array with items, can be a plain list or key, value pairs
isAsync Boolean false If retrieving API data asynchronously
minChar Number 2 Min. characters to type before popup shows
maxItems Number 10 Max. items to show in popup
fromStart Boolean true Match from the start or anywhere in the string

Slots

Slot Prop dependencies Description
default isAsync custom loading indication

Made with Svelte

It’s made with Svelte, which means you don’t need any JS framework. Just use the dist/index.js file in any Javascript project:

include the bundle:

  1. <script src="svelte-autocomplete/dist/index.js"></script>

create component like so:

  1. const myComponent = new AutoComplete({
  2. target: document.querySelector('#app'),
  3. data: {
  4. name: 'fruits',
  5. itemStart: 1,
  6. items: [...]
  7. }
  8. })