npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-tag-input

v0.0.1

Published

Customizable [Vue](https://vuejs.org) component for tag input, which support autocomplete.

Downloads

63

Readme

Vue Tag Input

Customizable Vue component for tag input, which support autocomplete.

Getting Started

npm install --save vue-tag-autocomplete // OR
yarn add vue-tag-autocomplete

Quick Example

<template>
  <vue-tag-input v-model="tags" :quick-mode="true"></vue-tag-input>
</template>

<script>
import VueTagInput from 'vue-tag-input'

export default {
  data() {
    return {
      tags: [
        'Africa',
        'Taiwan'
      ]
    }
  },
  components: {
    VueTagInput
  }
}
</script>

Usage

Props

tags - {Array<Object|String>} (required)

An array of tag objects. Each tag need an id and a text property which is used to display. Otherwise, you could just use array of strings directly. This component would generate id by index and string automatically.

// Recommended: Pass Object 
[
  {id: 1, name: 'Apple'},
  {id: 2, name: 'Banana'},
  ...
]
// Quick: Pass String 
[
  'Apple',
  'Banana',
  ...
]
//

suggestions - {Array<Object|String>}

Default: []
An array of suggestions that are used as basis for showing autocomplete. Each tag need an id and a text property which is used to display. Otherwise, you could just use array of strings directly. This component would generate id by index and string automatically.

// Recommended: Pass Object 
[
  {id: 1, name: 'Apple'},
  {id: 2, name: 'Banana'},
  ...
]
// Quick: Pass String 
[
  'Apple',
  'Banana',
  ...
]
//

quickMode - {Boolean}

Default: false
Allow developers to use v-model, rather than handling add and delete event by yourselves. In quick mode, new tag will append to array as string. If you want to control how new tag be added, you could listen change event. Otherwise, you should listen add and delete event instead.

<VueTagAutocomplete
  :quick-mode="true"
  v-model="tags"
/>
<!-- Which is equal to -->
<VueTagAutocomplete
  :quick-mode="true"
  :tags="tags"
  @change="val = { tags = val }"
/>

placeholder - {String}

Defaults to 'Add new tags'
The placeholder shown for the input.

delimiters - {Array}

Default: [9, 13] (Tab and return keys)
Array of integers matching keyboard event keyCode values. When a corresponding key is pressed, the preceding string is finalised as tag.

delimiterChars - {Array}

Default: [',']
Array of characters matching keyboard event key values. This is useful when needing to support a specific character irrespective of the keyboard layout. Note, that this list is separate from the one specified by the delimiters option, so you'll need to set the value there to [], if you wish to disable those keys.

onlyFromSuggestions - {Boolean}

Default: false
If set to true, it will be possible to add new items only from the autocomplete dropdown.

allowDuplicated - {Boolean}

Default: false
Allows users to add duplicated tags. If it's false, the duplicated tag would play animation with errorAninmatedClass to hint the user.

addOnBlur - {Boolean}

Default: false
Add tag automatically when input field blur.

errorAninmatedClass - {String}

Default: error (scoped css) The animation class would add on duplicated tag element when allowNew is false. The default animation is shaking for 0.25s.

Events

add

Params: tag would be added - {String}
Emitted when a tag had be added.

<template>
  <vue-tag-input :tags="tags" @add="onAdd"></vue-tag-input>
</template>

<script>
export default {
  data() {
    return { tags: [] }
  },
  methods: {
    onAddition(tag) {
      this.tags.push(tag)
    }
  }
}
</script>

delete

Params: index of tag would be removed - {Number}
Emitted when a tag had be added.

<template>
  <vue-tag-input :tags="tags" @delete="onDelete"></vue-tag-input>
</template>

<script>
export default {
  data() {
    return { tags: [] }
  },
  methods: {
    onDelete(index) {
      this.tags.splice(index, 1)
    }
  }
}
</script>  

change

Params: the array of updated tags - {Array}
Emitted when a tag had be added or deteled, which only be available in quickMode. The new tag will be appended as string into array. If you need to control new tag in the array, you could modify the last item of array and pass the whole array to data in the listener.

export default {
  data() {
    return { tags: [] }
  },
  methods: {
    onInput(newTags) {
      // newTags will contained the new array of updated tags. 
      const id = newTags.length - 1
      const text = newTags.pop()
      this.tags = [...newTags, {
        id,
        text
      }]
    }
  }
}

inputChange

Parmas: the current input data - {String}
Emitted when input field changed. You could query autocomplete data here.

export default {
  data() {
    return { 
      tags: [],
      suggestions: []
    }
  },
  methods: {
    onInputChange(query) {
      fetch(`https://your.data.source?query=${query}`, (data) => {
        this.suggestions = data
      })
    }
  }
}

Development

Author

Lucien Lee

License

MIT