Skip to content

Commit 225744f

Browse files
author
Damian Dulisz
committed
Improving code coverage
1 parent fd63fa6 commit 225744f

File tree

3 files changed

+660
-151
lines changed

3 files changed

+660
-151
lines changed

src/App.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<multiselect
2424
:options="source"
2525
:selected="value"
26-
:multiple="true"
26+
:multiple="false"
2727
:searchable="true"
2828
:placeholder="placeholder"
2929
label="name"
@@ -45,10 +45,10 @@ export default {
4545
options: ['Select option', 'options', 'selected', 'mulitple', 'label', 'searchable', 'clearOnSelect', 'hideSelected', 'maxHeight', 'allowEmpty', 'showLabels', 'onChange', 'touched'],
4646
selected: ['onChange'],
4747
multiple: true,
48-
searchable: false,
48+
searchable: true,
4949
placeholder: 'Select props',
5050
source: [{ name: '1' }, { name: '2' }, { name: '3' }],
51-
value: [{ name: '2' }]
51+
value: []
5252
}
5353
}
5454
}

src/components/Multiselect.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
watch: {
150150
'value' () {
151151
if (this.onChange) {
152+
console.log('on change', this.value)
152153
this.onChange(this.value)
153154
} else {
154155
this.$set('selected', this.value)
@@ -178,9 +179,7 @@
178179
select (option) {
179180
if (this.multiple) {
180181
if (this.isSelected(option)) {
181-
if (this.allowEmpty) {
182-
this.value.$remove(option)
183-
}
182+
this.removeElement(option)
184183
} else {
185184
this.value.push(option)
186185
if (this.clearOnSelect) { this.search = '' }
@@ -211,7 +210,9 @@
211210
}
212211
},
213212
removeElement (option) {
214-
this.value.$remove(option)
213+
if (this.allowEmpty || this.value.length > 1) {
214+
this.value.$remove(option)
215+
}
215216
},
216217
tryActivate () {
217218
if (!this.isOpen) {
@@ -245,7 +246,7 @@
245246
},
246247
removeLastElement () {
247248
if (this.search.length === 0 && Array.isArray(this.value)) {
248-
this.value.pop()
249+
this.removeElement(this.value[this.value.length - 1])
249250
}
250251
},
251252
addPointerElement () {

0 commit comments

Comments
 (0)