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
What It Does Not Do
Nope no regular selects. See vue-single-select for this.
No ajax loading.
Usage
Install and Use Via CDN
Choose a fruit!
Install Via NPM
$ npm i vue-taggable-select
Register it
In your component:
; components: VueTaggableSelect //...
Globally:
;Vue;
Use It
Use It Again
Use It Again
Dont like the Styling?
You can override some of it. Like so:
Then all you need to do is provide some class definitions like so:
... and so on.
Note: Bootstrap 3 Users May want to increase the size of the icons.
If so do this:
Kitchen Sink
Meh, see props below.
Why vue-taggable-select is better
-
It handles custom label/value props for displaying options.
Other select components require you to conform to their format. Which often means data wrangling.
-
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.
-
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
-
Lightweight
- Why are the other packages so big and actually have dependencies?
-
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.
-
Mine just looks nicer
A lot nicer!
-
It's simple!!
Available Props
props: // This corresponds to v-model value: required: true taggable: type: Boolean required: false false // Use classes to override the look and feel // Provide these EIGHT classes. classes: type: Object required: false { 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 "" // Your list of things for the select options: type: Array required: false // Tells vue-taggable-select what key to use // for generating option labels optionLabel: type: String required: false null // Tells vue-taggable-select the value // you want populated in the select for the // input optionKey: type: String required: false null // Give your input an html element id placeholder: type: String required: false "Search Here" maxHeight: type: String "220px" required: false //Give the input an id inputId: type: String "multi-select" required: false // Seed search text with initial value initial: type: String required: false null // Make it required required: type: Boolean required: false false // Max number of results to show. maxResults: type: Number required: false 30 //Meh tabindex: type: String required: false { return ""; } // Remove previously selected options // via the delete key keyboardDelete: type: Boolean required: false { return true; } // Tell vue-taggable-select how to display // selected options getOptionDescription: type: Function { if thisoptionKey && thisoptionLabel return optionthisoptionKey + " " + optionthisoptionLabel; if thisoptionLabel return optionthisoptionLabel; if thisoptionKey return optionthisoptionKey; return option; } // Use this to tell vue-taggable-select // the values are for doing a submit getOptionValue: type: Function { if thisoptionKey return optionthisoptionKey; if thisoptionLabel return optionthisoptionLabel; return option; }