A Multiple Taggable Select Autocomplete Dropdown Component for Vue

A Multiple Taggable Select Autocomplete Dropdown Component for Vue

vue-taggable-select A multiple taggable select autocomplete dropdown component for Vue

vue-taggable-select

A Vue component that makes long, unwieldy select boxes user friendly.

What it Does

vue-taggable-select provides an elegant, user-friendly component to replace long, unwieldy multi select elements. Great for users. Simple for developers.

How simple?

This simple:

This simple

<vue-taggable-select
    :taggable="true"
    v-model="fruit" 
    :options="['apple','cherry','banana','pear', 'tomato']"
></vue-taggable-select>

What It Does Not Do

Nope no regular selects. See vue-single-select for this.

Vue Single Select

No ajax loading.

Usage

Install and Use Via CDN

<div id="app">
    <lable>Choose a fruit!</lable>
    <vue-taggable-select
        v-model="fruit"
        :options="fruits"
    ></vue-taggable-select>
</div>
<script src="https://unpkg.com/[email protected]"></script>
<script src="https://unpkg.com/[email protected]"></script>
<script>
 new Vue({
     el:"#app",
     data: {
         fruit: null,
         fruits: ['peach','pear','apple','orange']
     }
 });
</script>

Install Via NPM

$ npm i vue-taggable-select

Register it

In your component:

import VueTaggableSelect from "vue-taggable-select";
export default {
components: {
     VueTaggableSelect
  },
  //...
}

Globally:

import VueTaggableSelect from "vue-taggable-select";
Vue.component('vue-taggable-select', VueTaggableSelect);

Use It

<vue-taggable-select
    make-it-taggable="good!"
    :taggable="true"
    v-model="fruit"
    :options="['apple','banana','cherry','tomato']"
    :required="true"
></vue-taggable-select>

Use It Again

<vue-taggable-select
        name="maybe"
        placeholder="pick a post"
        you-want-to-select-a-post="ok"
        v-model="post"
        out-of-all-these-posts="makes sense"
        :options="posts"
        a-post-has-an-id="good for search and display"
        option-key="id"
        the-post-has-a-title="make sure to show these"
        option-label="title"
></vue-taggable-select>

Use It Again

<vue-taggable-select
        you-want-to-select-a-reply="yes"
        v-model="reply"
        out-of-all-these-replies="yep"
        :options="replies"
        a-reply-only-has-a-reply="sounds about right"
        option-label="reply"
        seed-an-initial-value="what's seed mean?"
        initial="seed me"
        you-only-want-20-options-to-show="is 20 enough?"
        :max-results="20"
></vue-taggable-select>

Dont like the Styling?

You can override some of it. Like so:

<vue-taggable-select
        id="selected-reply"
        name="a_reply"
        option-label="reply"
        v-model="reply"
        :options="replies"
        you-like-huge-dropdowns="1000px is long!"
        max-height="1000px"
        :classes='{
            icons: "icons"
            active: "active",
            wrapper: "multi-select-wrapper",
            searchWrapper: "search-wrapper",
            searchInput: "search-input",
            pill: "pill",
            required: "required",
            dropdown: "dropdown"
        }'
></vue-taggable-select>

Then all you need to do is provide some class definitions like so:

.active {
    background-color: pink;
}
.multi-select-wrapper {
    display: block;
    font-size: 16px;
}
.search-input {
    color: black;
}
.pill {
    padding: .5em;
}

... and so on.

Note: Bootstrap 3 Users May want to increase the size of the icons.

If so do this:

.icons svg {
    height: 1em;
    width: 1em;
}

Kitchen Sink

Meh, see props below.

Why vue-taggable-select is better

  1. It handles custom label/value props for displaying options.

    Other select components require you to conform to their format. Which often means data wrangling.

  2. It's easier on the DOM.

    Other components will load up all the options available in the select element. This can be heavy. vue-taggable-select makes an executive decision that you probably will not want to scroll more than N options before you want to narrow things down a bit. You can change this, but the default is 30.

  3. Snappy Event Handling

    • up and down arrows for selecting options
    • enter to select first match
    • remembers selection on change
    • hit the escape key to, well, escape
    • hit delete to remove the last selection
  4. Lightweight

    • Why are the other packages so big and actually have dependencies?
  5. It works for regular 'POST backs' to the server.

    If you are doing a regular post or just gathering the form data you don't need to do anything extra to provide a name and value for the selected option.

  6. Mine just looks nicer

    A lot nicer!

  7. It's simple!!

Available Props

props: {
    // This corresponds to v-model
    value: {
        required: true
    },
    taggable: {
        type: Boolean,
        required: false,
        default: () => false
    },
    // Use classes to override the look and feel
    // Provide these EIGHT classes.
    classes: {
        type: Object,
        required: false,
        default: () => {
            return {
                icons: 'icons',
                active: 'active',
                wrapper: "multi-select-wrapper",
                searchWrapper: "search-wrapper",
                searchInput: "search-input",
                pill: "pill",
                required: "required",
                dropdown: "dropdown"
            };
        }
    },
    // Give your input a name
    // Good for posting forms
    name: {
        type: String,
        required: false,
        default: () => ""
    },
    // Your list of things for the select   
    options: {
        type: Array,
        required: false,
        default: () => []
    },
    // Tells vue-taggable-select what key to use
    // for generating option labels
    optionLabel: {
        type: String,
        required: false,
        default: () => null
    },
    // Tells vue-taggable-select the value
    // you want populated in the select for the 
    // input
    optionKey: {
        type: String,
        required: false,
        default: () => null
    },
    // Give your input an html element id
    placeholder: {
        type: String,
        required: false,
        default: () => "Search Here"
    },
    maxHeight: {
        type: String,
        default: () => "220px",
        required: false
    },
    //Give the input an id
    inputId: {
        type: String,
        default: () => "multi-select",
        required: false
    },
    // Seed search text with initial value
    initial: {
        type: String,
        required: false,
        default: () => null
    },
    // Make it required
    required: {
        type: Boolean,
        required: false,
        default: () => false
    },
    // Max number of results to show.
    maxResults: {
        type: Number,
        required: false,
        default: () => 30
    },
    //Meh
    tabindex: {
        type: String,
        required: false,
        default: () => {
            return "";
        }
    },
    // Remove previously selected options
    // via the delete key
    keyboardDelete: {
        type: Boolean,
        required: false,
        default: () => {
            return true;
        }
    },
    // Tell vue-taggable-select how to display
    // selected options
    getOptionDescription: {
        type: Function,
        default(option) {
            if (this.optionKey && this.optionLabel) {
                return option[this.optionKey] + " " + option[this.optionLabel];
            }
            if (this.optionLabel) {
                return option[this.optionLabel];
            }
            if (this.optionKey) {
                return option[this.optionKey];
            }
            return option;
        }
    },
    // Use this to tell vue-taggable-select
    // the values are for doing a submit
    getOptionValue: {
        type: Function,
        default(option) {
            if (this.optionKey) {
                return option[this.optionKey];
            }

            if (this.optionLabel) {
                return option[this.optionLabel];
            }

            return option;
        }
    }
},

Download Details:

Author: robrogers3

Demo: https://codesandbox.io/s/18jz68zn77

Source Code: https://github.com/robrogers3/vue-taggable-select

vue vuejs javascript

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

8 Popular Websites That Use The Vue.JS Framework

In this article, we are going to list out the most popular websites using Vue JS as their frontend framework. Vue JS is one of those elite progressive JavaScript frameworks that has huge demand in the web development industry. Many popular websites are developed using Vue in their frontend development because of its imperative features.

Vue Native is a framework to build cross platform native mobile apps using JavaScript

Vue Native is a framework to build cross platform native mobile apps using JavaScript. It is a wrapper around the APIs of React Native. So, with Vue Native, you can do everything that you can do with React Native. With Vue Native, you get

How to Make a Simple Vue Custom Select Component

In this article, you’ll learn how to build a Vue custom select component that can be easily be styled using your own CSS. In fact, it’s the same component that we use in production on Qvault, and you can see it in action on the playground.

Creating a Custom Tooltip Component in Vue

There are plenty of libraries out there that will have you up and running with a good tooltip solution in minutes. However, if you are like me, you are sick and tired of giant dependency trees that have the distinct possibility of breaking at any time.

Vue ShortKey plugin for Vue.js

Vue-ShortKey - The ultimate shortcut plugin to improve the UX .Vue-ShortKey - plugin for VueJS 2.x accepts shortcuts globaly and in a single listener.