Socket
Socket
Sign inDemoInstall

svelte-tags-input

Package Overview
Dependencies
0
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    svelte-tags-input

Fully customizable Svelte component to enter tags.


Version published
Weekly downloads
1.2K
increased by16.1%
Maintainers
1
Install size
120 kB
Created
Weekly downloads
 

Changelog

Source

6.0.0

  • Fix: #87
  • Add: onTagAdded and onTagRemoved events. #77
  • Add: cleanOnBlur prop. #83
  • Add: customValidation prop. #89
  • Fix: Form submitting when tag clicked #88
  • Fix: https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#missing-exports-condition #90

Readme

Source

Svelte Tags Input

svelte-tags-input

Svelte tags input is a component to use with Svelte and easily enter tags and customize some options

Live Demo

Install & Usage

npm install svelte-tags-input
import Tags from "svelte-tags-input";

<Tags />

Options

OptionTypeDefaultDescription
bind:tagsArray[]To get the values
addKeysArrayENTER 13Set which keys add new values
removeKeysArrayBACKSPACE 8Set which keys remove new values
allowPasteBooleanfalseEnable pasting of a tag or tag group
allowDropBooleanfalseEnable drag and drop of a tag or tag group
splitWithString,Choose what character split you group of tags
Work only if allowDrop or allowPaste are true
maxTagsNumberfalseSet maximum number of tags
onlyUniqueBooleanfalseSet the entered tags to be unique
placeholderStringfalseSet a placeholder
autoCompleteArray or fn()falseSet an array of elements to create a auto-complete dropdown
autoCompleteKeyStringfalseSet a key to search on autoComplete array of objects
autoCompleteFilterBooleantrueIf false disable auto complete filter and return endpoint response without filter
onlyAutocompleteBooleanfalseOnly accept tags inside the auto complete list
nameStringsvelte-tags-inputSet a name attribute
idStringRandom Unique IDSet a id attribute
allowBlurBooleanfalseEnable add tag when input blur
disableBooleanfalseDisable input
minCharsNumber1Minimum length of search text to show autoComplete list. If 0, autoComplete list shows all results when click on input
labelTextStringsvelte-tags-inputCustom text for input label
labelShowBooleanfalseIf true the label will be visible
readonlyBooleanfalseIf true the input show in display mode
onTagClickFunctionemptyA function to fire when a tag is clicked
autoCompleteShowKeyStringautoCompleteKeyA key string to show a different value from auto complete list object returned
onTagAddedFunctionemptyGet a function to execute when tag added
onTagRemovedFunctionemptyGet a function to execute when tag removed
cleanOnBlurBooleanfalseClear input on blur (tags keeped)
customValidationFunctionemptyCreate a custom validation when tag is added
A complete list of key codes

Full example

Live Demo

import Tags from "svelte-tags-input";

let tags = [];

const countryList = [
    "Afghanistan",
    "Albania",
    "Algeria",
    "American Samoa",
    "Andorra",
    "Angola",
    "Anguilla",
    "Antarctica",
    "Antigua and Barbuda",
    "Argentina"
    ...
];

<Tags
    bind:tags={tags}
    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.
    readonly={false} // Just to illustrate. No need to declare it if it's false.
    minChars={3}
    onlyAutocomplete
    labelText="Label"
    labelShow
    onTagClick={tag => console.log(tag)}
    onTagAdded={(tag, tags) => console.log(tag, tags)}
    onTagRemoved={(tag, tags) => console.log(tag, tags)}
	cleanOnBlur={true}
	customValidation={(tag) => tag === "Argentina" ? true : false }
/>

Example with autoComplete function

Live Demo

import Tags from "svelte-tags-input";

let tags = [];

const customAutocomplete = async () => {
    const list = await fetch('https://restcountries.com/v2/all?fields=name,alpha3Code,flag');
    const res = await list.json();

    return res;
}

<Tags
    bind:tags={tags}
    autoComplete={customAutocomplete}
    autoCompleteKey={"name"}
    autoCompleteShowKey={"alpha3Code"}
/>

{#each tags as country, index}
    <p>{index} - {country.name} - {country.alpha3Code} </p>
    <img src={country.flag} />
{/each}

FAQs

CHANGELOG

License

This project is open source and available under the MIT License.

Author

Agustín

2024

Keywords

FAQs

Last updated on 26 Jan 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc