Fully customizable Svelte component to enter tags.
npm install @cwlogo/svelte-tags-input``bash`
npm install svelte-tags-input --save
`javascript
import Tags from "svelte-tags-input";
`
| Option | Type | Default | Description |
| --- | --- | --- | --- |
| on:tags | Function | undefined | To get the values |Array
| addKeys | | ENTER 13 | Set which keys add new values |Array
| removeKeys | | BACKSPACE 8 | Set which keys remove new values |Boolean
| allowPaste | | false | Enable pasting of a tag or tag group |Boolean
| allowDrop | | false | Enable drag and drop of a tag or tag group |String
| splitWith | | , | Choose what character split you group of tagsNumber
_Work only if allowDrop or allowPaste are true_ |
| maxTags | | false | Set maximum number of tags |Boolean
| onlyUnique | | false | Set the entered tags to be unique |String
| placeholder | | false | Set a placeholder |Array
| autoComplete | or fn() | false | Set an array of elements to create a auto-complete dropdown |String
| autoCompleteKey | | false | Set a key to search on autoComplete array of objects |Boolean
| autoCompleteFilter | | true | If false disable auto complete filter and return endpoint response without filter |Boolean
| onlyAutocomplete | | false | Only accept tags inside the auto complete list |String
| name | | svelte-tags-input | Set a name attribute |String
| id | | Random Unique ID | Set a id attribute |Boolean
| allowBlur | | false | Enable add tag when input blur |Boolean
| disable | | false | Disable input |Number
| minChars | | 1 | Minimum length of search text to show autoComplete list. If 0, autoComplete list shows all results when click on input |String
| labelText | | svelte-tags-input | Custom text for input label |Boolean
| labelShow | | false | If true the label will be visible |
##### A complete list of key codes
`javascript
import Tags from "svelte-tags-input";
// If on:tags is defined
let tag = "";
function handleTags(event) {
tag = event.detail.tags;
}
const countryList = [
"Afghanistan",
"Albania",
"Algeria",
"American Samoa",
"Andorra",
"Angola",
"Anguilla",
"Antarctica",
"Antigua and Barbuda",
"Argentina"
...
];
addKeys={[9]} // TAB Key
maxTags={3}
allowPaste={true}
allowDrop={true}
splitWith={"/"}
onlyUnique={true}
removeKeys={[27]} // ESC Key
placeholder={"Svelte Tags Input full example"}
autoComplete={countryList}
name={"custom-name"}
id={"custom-id"}
allowBlur={true}
disable={false} // Just to illustrate. No need to declare it if it's false.
minChars={3}
onlyAutocomplete
labelText="Label"
labelShow
/>
`
function`javascript
import Tags from "svelte-tags-input";
let tag = "";
function handleTags(event) {
tag = event.detail.tags;
}
const customAutocomplete = async () => {
const list = await fetch('https://restcountries.com/v2/all?fields=name,alpha3Code,flag');
const res = await list.json();
return res;
}
autoComplete={customAutocomplete}
autoCompleteKey={"name"}
/>
{#each tag as country, index}
{index} - {country.name}
This project is open source and available under the MIT License.
##### 2022