Giter Club home page Giter Club logo

tag-input's Introduction

TagInput

A versatile tag input component built with Vue 3 Composition API.

Version codecov Downloads npm bundle size Publish to npm and GitHub Get help

tag-input.gif

Features

  • ✅ No dependencies
  • ✅ Input box stays focused - no need to re-focus the input => better UX
  • ✅ Autocompletion
  • ✅ Use arrow keys to navigate and enter key to select autocompleteItems
  • ✅ Fast setup
  • ✅ Customize tag validator
  • ✅ Works with Vuex
  • ✅ Small size: 1.6 kB gzipped
  • ✅ Many customization options
  • ✅ Delete tags on backspace / delete key
  • ✅ Confirm before delete - tags turns red when backspace is pressed, gets deleted when backspace is pressed again
  • ✅ Works well with copy & paste
  • ✅ Excellent UX and accessibility
  • ✅ Examples & Docs

Please read this article to learn how to build this package step by step and the background story.

To learn vue js please check out our courses Vue.js Complete Course + Guide and Vue 3 Essentials

Follow us on FaceBook to get the latest discount coupons and update to our articles and packages.

To keep it thin and performant we have chosen to provide only the minified version. Because, that's what you really need. In case you are looking for the full version build your own from this source code as per Build section.

live demo

Install

NPM

npm i @mayank1513/vue-tag-input --production

or

pnpm i @mayank1513/vue-tag-input --production

or

yarn add @mayank1513/vue-tag-input --production

CDN

<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script src="https://unpkg.com/@mayank1513/vue-tag-input"></script>
<link rel="stylesheet" href="https://unpkg.com/@mayank1513/[email protected]/dist/style.css">

Usage

npm

<template>
  ...
  <tag-input v-model="tags" />
  ...
</template>

<script>
import TagInput from '@mayank1513/vue-tag-input'
import '@mayank1513/vue-tag-input/style.css'
...

export default {
  name: 'App',
  data() {
    return {
      tags: [],
      ...
    };
  },
  components: {
    TagInput,
    ...
  },
  ...
}
</script>

Detailed Docs available at (https://vue-tag-input.vercel.app)[https://vue-tag-input.vercel.app]

cdn

basic usage

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vue Tag Input Demo</title>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script src="https://unpkg.com/@mayank1513/vue-tag-input"></script>
    <link
      rel="stylesheet"
      href="https://unpkg.com/@mayank1513/[email protected]/style.css"
    />
  </head>

  <body>
    <div id="app">
      <tag-input></tag-input>
    </div>
  </body>
  <script>
    Vue.createApp({
      components: {
        TagInput,
      },
    }).mount("#app");
  </script>
</html>

advanced usage

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script src="https://unpkg.com/@mayank1513/vue-tag-input"></script>
    <link
      rel="stylesheet"
      href="https://unpkg.com/@mayank1513/[email protected]/style.css"
    />
    <style>
      #app {
        font-family: Avenir, Helvetica, Arial, sans-serif;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        text-align: center;
        color: #2c3e50;
        margin-top: 60px;
        max-width: 1400px;
        margin: auto;
      }

      .main {
        text-align: start;
      }
    </style>
  </head>

  <body>
    <div id="app">
      <img
        class="logo"
        alt="Krishna Apps logo"
        src="https://raw.githubusercontent.com/mayank1513/tag-input/master/src/assets/logo.png"
      />
      <br />
      <h2>Presents</h2>
      <h1>Vue Tag Input</h1>
      <hr />
      <div class="main">
        <h1>Default options</h1>
        <tag-input v-model="tags" />
        <br />
        <span
          >Use <code>enter</code> key or <code>tab</code> key to create a new
          tag.</span
        >
        <h1>With custom delimiter and colors</h1>
        <tag-input
          tagBgColor="lightgreen"
          tagTextColor="darkgreen"
          :customDelimiter="customDelimiter"
          v-model="tags"
        />
        <br />
        <span
          >Use <code>enter</code> key or <code>tab</code> key or any of the
          custom delimeters to create a new tag.</span
        >
        <p>
          Custom delimiters:
          <code v-for="delim in customDelimiter" :key="delim">
            "{{delim}}"</code
          >
        </p>
        <br />
        <h1>Do not allow custom tags</h1>
        <tag-input
          :autocomplete-items="autocompleteItems"
          validator="onlyAutocompleteItems"
          tagBgColor="blue"
          tagTextColor="lightblue"
          :customDelimiter="customDelimiter"
          v-model="tags"
        />
        <br />
        Try entering tag that is not in autocompleteItems and hit
        <code>enter</code>
        <br />
        <span
          >Use <code>enter</code> key or <code>tab</code> key or any of the
          custom delimeters to create a new tag.</span
        >
        <p>
          Allowed Tags:
          <code v-for="tag in autocompleteItems" :key="tag"> "{{tag}}"</code>
        </p>
        <p>
          Custom delimiters:
          <code v-for="delim in customDelimiter" :key="delim">
            "{{delim}}"</code
          >
        </p>
        <br />
        <h1>
          Provide autocompleteItems for autofill but also allow custom tags
        </h1>
        <tag-input
          :autocomplete-items="autocompleteItems"
          tagBgColor="blue"
          tagTextColor="lightblue"
          :customDelimiter="customDelimiter"
          v-model="tags"
        />
        <br />
        <span
          >Use <code>enter</code> key or <code>tab</code> key or any of the
          custom delimeters to create a new tag.</span
        >
        <p>
          Allowed Tags:
          <code v-for="tag in autocompleteItems" :key="tag"> "{{tag}}"</code>
        </p>
        <p>
          Custom delimiters:
          <code v-for="delim in customDelimiter" :key="delim">
            "{{delim}}"</code
          >
        </p>
        <br />
      </div>
    </div>

    <script>
      Vue.createApp({
        data() {
          return {
            tags: [],
            customDelimiter: [",", " "],
            autocompleteItems: [
              "vue",
              "composition",
              "js",
              "mytag1",
              "mayank1513",
            ],
          };
        },
        components: {
          TagInput,
        },
      }).mount("#app");
    </script>
  </body>
</html>

Build

To build the example clone the repo git clone https://github.com/mayank1513/tag-input.git and run

npm i && npm run build
// or
pnpm i && npm run build

Contribute

Todo

  • Update docs

Help us to help you more

Contribute for a Cause

Alt

License

Licensed as MIT open source. Copyright © 2023 Mayank Kumar Chaudhari


with 💖 by Mayank Kumar Chaudhari

tag-input's People

Contributors

mayank1513 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

tag-input's Issues

Input Validation

Need a property, preferably a function type, that can be called to validate the input before accepting the input as a tag.

Autocomplete as function

Can you change the autocomplete to be an array OR a function? If it is set to a function, call it with the text from the input as a parameter. So we can run autocomplete against a third-party rest api.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.