Skip to content

Commit 772c684

Browse files
author
Damian Dulisz
committed
Small adjustments after #37 and added test case
1 parent 9a0d7aa commit 772c684

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/multiselectMixin.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,12 @@ module.exports = {
241241
},
242242
computed: {
243243
filteredOptions () {
244-
let search = this.search ? this.search : ''
245-
var options = this.hideSelected
244+
let search = this.search || ''
245+
let options = this.hideSelected
246246
? this.options.filter(this.isNotSelected)
247247
: this.options
248-
options = this.$options.filters.filterBy(options, search)
249-
if (this.taggable && search.length > 0 && !this.isExistingOption(search)) {
248+
options = this.$options.filters.filterBy(options, this.search)
249+
if (this.taggable && search.length && !this.isExistingOption(search)) {
250250
options.unshift({ isTag: true, label: search })
251251
}
252252
return options

test/unit/specs/Multiselect.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,18 @@ describe('Multiselect.vue', () => {
148148
expect(vm.$children[0].search).to.equal(2)
149149
expect(vm.$children[0].$els.search.value).to.equal('2')
150150
})
151+
it('if selected is null should set search value to empty string', () => {
152+
const vm = new Vue({
153+
template: '<multiselect :selected="value" :options="source" label="id" key="id" :taggable="true"></multiselect>',
154+
components: { Multiselect },
155+
data: {
156+
value: null,
157+
source: [1, 2, 3]
158+
}
159+
}).$mount()
160+
expect(vm.$children[0].search).to.equal(null)
161+
expect(vm.$children[0].$els.search.value).to.equal('')
162+
})
151163
})
152164
})
153165
describe('when searchable == FALSE', () => {

0 commit comments

Comments
 (0)