vue-multiselect
The most complete selecting solution for Vue.js, without jQuery.
Current version: 1.1.4
For Vue 2.0 users:
Vue-multiselect 2.0-beta is available: npm install vue-multiselect@next
.
API changes:
- Instead of Vue.partial for custom option templates you can use a custom render function.
- The
:key
props has changed to :track-by
, due to conflicts with Vue 2.0. - Added support for
v-model
@update
has changed to @input
to also work with v-model:selected
has changed to :value
for the same reason
Important Breaking Change
- As of beta.14 styles have to be required separately due to SSR support.
<style src="vue-multiselect/dist/vue-multiselect.min.css"></style>
Features & characteristics:
- NO dependencies
- Single select
- Multiple select
- Tagging
- Custom option templates (1.1.0+)
- Dropdowns
- Filtering
- Search with suggestions
- Logic split into mixins
- Basic component and support for custom components
- Vuex support
- Async options support
- > 99% test coverage
- Fully configurable (see props list below)
Demo & docs
http://monterail.github.io/vue-multiselect/
Install & basic usage
npm install vue-multiselect
<template>
<div>
<multiselect
:selected="selected"
:options="options"
@update="updateSelected">
</multiselect>
</div>
</template>
import Multiselect from 'vue-multiselect'
export default {
components: { Multiselect },
data () {
return {
selected: null,
options: ['list', 'of', 'options']
}
},
methods: {
updateSelected (newSelected) {
this.selected = newSelected
}
}
}
Alternatively:
<script src="https://cdn.jsdelivr.net/vue.multiselect/1.1.4/vue-multiselect.min.js"></script>
VueMultiselect will be available on the window object. As it contains a default export you have to access it through VueMultiselect.default
.
Vue.component('Multiselect', VueMultiselect.default)
You can now author custom components based on vue-multiselect mixins.
import { multiselectMixin, pointerMixin } from 'vue-multiselect'
export default {
mixins: [multiselectMixin, pointerMixin],
data () {
return {
selected: null,
options: ['list', 'of', 'options']
}
}
}
Roadmap:
- Grouping
- Examples of custom components / templates ready to use in project
Examples
in jade-lang/pug-lang
Single select / dropdown
multiselect(
:options="source",
:selected="value",
:searchable="false",
:close-on-select="false",
:allow-empty="false",
@update="updateSelected",
label="name",
placeholder="Select one",
key="name"
)
Single select with search
multiselect(
:options="source",
:selected="value",
:close-on-select="true",
@update="updateValue",
placeholder="Select one",
label="name",
key="name"
)
Multiple select with search
multiselect(
:options="source",
:selected="multiValue",
:multiple="true",
:close-on-select="true",
@update="updateMultiValue",
placeholder="Pick some",
label="name",
key="name"
)
Tagging
with @tag
event
multiselect(
:options="taggingOptions",
:selected="taggingSelected",
:multiple="true",
:taggable="true",
@tag="addTag",
@update="updateSelectedTagging",
tag-placeholder="Add this as new tag",
placeholder="Type to search or add tag",
label="name",
key="code"
)
addTag (newTag) {
const tag = {
name: newTag,
code: newTag.substring(0, 2) + Math.floor((Math.random() * 10000000))
}
this.taggingOptions.push(tag)
this.taggingSelected.push(tag)
},
Custom option template
Using partial API
multiselect(
:options="styleList",
:selected="selectedStyle",
:option-height="130",
:custom-label="styleLabel",
@update="updateSelectedStyle",
option-partial="customOptionPartial"
placeholder="Fav No Man’s Sky path"
label="title"
key="title"
)
import customOptionPartial from './partials/customOptionPartial.html'
Vue.partial('customOptionPartial', customOptionPartial)
methods: {
styleLabel ({ title, desc }) {
return `${title} – ${desc}`
},
updateSelectedStyle (style) {
this.selectedStyle = style
}
}
<div>
<img class="option__image" :src="option.img" alt="No Man’s Sky" />
<div class="option__desc">
<span class="option__title">{{ option.title }}</span>
<span class="option__small">
{{ option.desc }}
</span>
</div>
</div>
Asynchronous dropdown
multiselect(
:options="countries",
:selected="selectedCountries",
:multiple="multiple",
:searchable="searchable",
@search-change="asyncFind",
placeholder="Type to search",
label="name"
key="code"
)
span(slot="noResult").
Oops! No elements found. Consider changing the search query.
methods: {
asyncFind (query) {
this.countries = findService(query)
}
}
Props config
props: {
options: {
type: Array,
required: true
},
multiple: {
type: Boolean,
default: false
},
selected: {},
key: {
type: String,
default: false
},
label: {
type: String,
default: false
},
searchable: {
type: Boolean,
default: true
},
clearOnSelect: {
type: Boolean,
default: true
},
hideSelected: {
type: Boolean,
default: false
},
placeholder: {
type: String,
default: 'Select option'
},
maxHeight: {
type: Number,
default: 300
},
allowEmpty: {
type: Boolean,
default: true
},
resetAfter: {
type: Boolean,
default: false
},
closeOnSelect: {
type: Boolean,
default: true
},
customLabel: {
type: Function,
default: false
},
taggable: {
type: Boolean,
default: false
},
tagPlaceholder: {
type: String,
default: 'Press enter to create a tag'
},
max: {
type: Number,
default: false
},
id: {
default: null
},
optionsLimit: {
type: Number,
default: 1000
}
}
props: {
showPointer: {
type: Boolean,
default: true
}
},
props: {
selectLabel: {
type: String,
default: 'Press enter to select'
},
selectedLabel: {
type: String,
default: 'Selected'
},
deselectLabel: {
type: String,
default: 'Press enter to remove'
},
showLabels: {
type: Boolean,
default: true
},
limit: {
type: Number,
default: 99999
},
limitText: {
type: Function,
default: count => `and ${count} more`
},
loading: {
type: Boolean,
default: false
},
disabled: {
type: Boolean,
default: false
}
}
Contributing
npm run dev
npm run bundle
npm run docs
npm run test
npm run unit-watch
For detailed explanation on how things work, checkout the guide and docs for vue-loader.
License
MIT
Copyright (c) 2016 Damian Dulisz