2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-05-17 02:29:37 +03:00

Merge pull request #172 from koriroys/master

Add option to allow closing a multi-select when a value is selected
This commit is contained in:
Jeff
2017-04-19 18:41:24 -07:00
committed by GitHub
4 changed files with 63 additions and 1 deletions
+2
View File
@@ -34,6 +34,8 @@
<v-select placeholder="multiple" multiple :options="options"></v-select>
<v-select placeholder="multiple, taggable" multiple taggable :options="options" no-drop></v-select>
<v-select placeholder="multiple, taggable, push-tags" multiple push-tags taggable :options="[{label: 'Foo', value: 'foo'}]"></v-select>
<v-select placeholder="multiple, closeOnSelect=true" multiple :options="['cat', 'dog', 'bear']"></v-select>
<v-select placeholder="multiple, closeOnSelect=false" multiple :close-on-select="false" :options="['cat', 'dog', 'bear']"></v-select>
<v-select placeholder="unsearchable" :options="options" :searchable="false"></v-select>
<v-select placeholder="search github.." label="full_name" @search="search" :options="ajaxRes"></v-select>
</div>
+10
View File
@@ -71,6 +71,16 @@
default: true
},
/**
* Close a dropdown when an option is chosen. Set to false to keep the dropdown
* open (useful when combined with multi-select, for example)
* @type {Boolean}
*/
closeOnSelect: {
type: Boolean,
default: true
},
/**
* Tells vue-select what key to use when generating option labels when
* `option` is an object.
+11 -1
View File
@@ -390,6 +390,16 @@
default: true
},
/**
* Close a dropdown when an option is chosen. Set to false to keep the dropdown
* open (useful when combined with multi-select, for example)
* @type {Boolean}
*/
closeOnSelect: {
type: Boolean,
default: true
},
/**
* Tells vue-select what key to use when generating option
* labels when each `option` is an object.
@@ -625,7 +635,7 @@
* @return {void}
*/
onAfterSelect(option) {
if (!this.multiple) {
if (this.closeOnSelect) {
this.open = !this.open
this.$refs.search.blur()
}
+40
View File
@@ -351,6 +351,46 @@ describe('Select.vue', () => {
})
})
it('closes the dropdown when an option is selected, multiple is true, and closeOnSelect option is true', (done) => {
const vm = new Vue({
template: '<div><v-select ref="select" :options="options" multiple :value="value"></v-select></div>',
components: {vSelect},
data: {
value: [],
options: ['one', 'two', 'three']
}
}).$mount()
vm.$children[0].open = true
vm.$refs.select.select('one')
Vue.nextTick(() => {
expect(vm.$children[0].open).toEqual(false)
done()
})
})
it('does not close the dropdown when the el is clicked, multiple is true, and closeOnSelect option is false', (done) => {
const vm = new Vue({
template: '<div><v-select ref="select" :options="options" multiple :closeOnSelect="false" :value="value"></v-select></div>',
components: {vSelect},
data: {
value: [],
options: ['one', 'two', 'three']
}
}).$mount()
vm.$children[0].open = true
vm.$refs.select.select('one')
Vue.nextTick(() => {
expect(vm.$children[0].open).toEqual(true)
done()
})
})
it('should close the dropdown on search blur', () => {
const vm = new Vue({
template: '<div><v-select :options="options" multiple :value="value"></v-select></div>',