Skip to content

Commit ecd76ce

Browse files
committed
improving name for should-dropdown-close option. adding test
1 parent 897b0d8 commit ecd76ce

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

dev.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
<v-select placeholder="multiple" multiple :options="options"></v-select>
3535
<v-select placeholder="multiple, taggable" multiple taggable :options="options" no-drop></v-select>
3636
<v-select placeholder="multiple, taggable, push-tags" multiple push-tags taggable :options="[{label: 'Foo', value: 'foo'}]"></v-select>
37-
<v-select placeholder="multiple, closeOnSelect" multiple :close-on-multi-select="true" :options="['cat', 'dog', 'bear']"></v-select>
37+
<v-select placeholder="multiple, closeOnSelect=true" multiple :options="['cat', 'dog', 'bear']"></v-select>
38+
<v-select placeholder="multiple, closeOnSelect=false" multiple :close-on-select="false" :options="['cat', 'dog', 'bear']"></v-select>
3839
<v-select placeholder="unsearchable" :options="options" :searchable="false"></v-select>
3940
<v-select placeholder="search github.." label="full_name" @search="search" :options="ajaxRes"></v-select>
4041
</div>

src/components/Select.vue

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -391,13 +391,13 @@
391391
},
392392
393393
/**
394-
* Allows user to choose to close the select dropdown when an option is selected.
395-
* set to true when multiple=true to close the dropdown between each selection
394+
* Close a dropdown when an option is select. Set to false to keep the dropdown
395+
* open (useful when combined with multi-select, for example)
396396
* @type {Boolean}
397397
*/
398-
closeOnMultiSelect: {
398+
closeOnSelect: {
399399
type: Boolean,
400-
default: false
400+
default: true
401401
},
402402
403403
/**
@@ -635,12 +635,7 @@
635635
* @return {void}
636636
*/
637637
onAfterSelect(option) {
638-
if (this.multiple) {
639-
if (this.closeOnMultiSelect) {
640-
this.open = !this.open
641-
this.$refs.search.blur()
642-
}
643-
} else {
638+
if (this.closeOnSelect) {
644639
this.open = !this.open
645640
this.$refs.search.blur()
646641
}

test/unit/specs/Select.spec.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,10 @@ describe('Select.vue', () => {
351351
})
352352
})
353353

354-
it('can close the dropdown when the el is clicked, multiple is true, and multipleCloseOnSelect option is true', (done) => {
354+
355+
it('closes the dropdown when an option is selected, multiple is true, and closeOnSelect option is true', (done) => {
355356
const vm = new Vue({
356-
template: '<div><v-select ref="select" :options="options" multiple closeOnMultiSelect :value="value"></v-select></div>',
357+
template: '<div><v-select ref="select" :options="options" multiple :value="value"></v-select></div>',
357358
components: {vSelect},
358359
data: {
359360
value: [],
@@ -370,6 +371,25 @@ describe('Select.vue', () => {
370371
})
371372
})
372373

374+
it('does not close the dropdown when the el is clicked, multiple is true, and closeOnSelect option is false', (done) => {
375+
const vm = new Vue({
376+
template: '<div><v-select ref="select" :options="options" multiple :closeOnSelect="false" :value="value"></v-select></div>',
377+
components: {vSelect},
378+
data: {
379+
value: [],
380+
options: ['one', 'two', 'three']
381+
}
382+
}).$mount()
383+
384+
vm.$children[0].open = true
385+
vm.$refs.select.select('one')
386+
387+
Vue.nextTick(() => {
388+
expect(vm.$children[0].open).toEqual(true)
389+
done()
390+
})
391+
})
392+
373393

374394
it('should close the dropdown on search blur', () => {
375395
const vm = new Vue({

0 commit comments

Comments
 (0)