Skip to content

Commit 75c7711

Browse files
author
Damian Dulisz
committed
Also remove throttle from the docs.
1 parent a983a25 commit 75c7711

File tree

3 files changed

+18
-34
lines changed

3 files changed

+18
-34
lines changed

docs/main.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,6 @@ import Multiselect from 'vue-multiselect'
66

77
import './docs.scss'
88

9-
function throttle (callback, limit) {
10-
var wait = false
11-
return function () {
12-
if (!wait) {
13-
callback.call()
14-
wait = true
15-
setTimeout(function () {
16-
wait = false
17-
}, limit)
18-
}
19-
}
20-
}
21-
229
function calculateNavPositions () {
2310
sections = Array
2411
.from(document.querySelectorAll('[data-section]'))
@@ -92,7 +79,7 @@ new Vue({
9279
},
9380
mounted () {
9481
this.adjustNav()
95-
window.addEventListener('scroll', throttle(this.adjustNav, 50))
82+
window.addEventListener('scroll', this.adjustNav)
9683
setTimeout(function () {
9784
calculateNavPositions()
9885
}, 1000)

src/Multiselect.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
@keyup.esc="deactivate()"
4545
@keydown.down.prevent="pointerForward()"
4646
@keydown.up.prevent="pointerBackward()"
47-
@keydown.enter.tab.stop.self.prevent="addPointerElement($event)"
47+
@keydown.enter.prevent
48+
@keydown.enter.tab.stop.self="addPointerElement($event)"
4849
@keydown.delete="removeLastElement()"
4950
class="multiselect__input"/>
5051
<span

src/multiselectMixin.js

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import deepClone from './utils'
33
function includes (str, query) {
44
if (!str) return false
55
const text = str.toString().toLowerCase()
6-
return text.indexOf(query) !== -1
6+
return text.indexOf(query.trim()) !== -1
77
}
88

99
function filterOptions (options, search, label) {
@@ -274,7 +274,7 @@ module.exports = {
274274
const search = this.search || ''
275275
const normalizedSearch = search.toLowerCase()
276276

277-
let options = this.options
277+
let options = this.options.concat()
278278

279279
if (this.internalSearch) {
280280
options = this.groupValues
@@ -306,14 +306,14 @@ module.exports = {
306306
: options.map(element => element.toString().toLowerCase())
307307
},
308308
currentOptionLabel () {
309-
return this.getOptionLabel(this.internalValue[0]) + ''
309+
return this.multiple ? '' : this.getOptionLabel(this.internalValue[0]) + ''
310310
}
311311
},
312312
watch: {
313-
'internalValue' () {
314-
if (this.resetAfter) {
315-
this.internalValue = []
313+
'internalValue' (newVal, oldVal) {
314+
if (this.resetAfter && this.internalValue.length) {
316315
this.search = ''
316+
this.internalValue = []
317317
}
318318
this.adjustSearch()
319319
},
@@ -328,6 +328,11 @@ module.exports = {
328328
}
329329
},
330330
methods: {
331+
getValue () {
332+
return this.multiple
333+
? deepClone(this.internalValue)
334+
: deepClone(this.internalValue[0])
335+
},
331336
/**
332337
* Filters and then flattens the options list
333338
* @param {Array}
@@ -351,7 +356,7 @@ module.exports = {
351356
)(options)
352357
},
353358
updateSearch (query) {
354-
this.search = query.trim().toString()
359+
this.search = query.toString()
355360
},
356361
/**
357362
* Finds out if the given query is already present
@@ -424,10 +429,7 @@ module.exports = {
424429
this.internalValue = [option]
425430
}
426431
this.$emit('select', deepClone(option), this.id)
427-
const value = this.multiple
428-
? this.internalValue
429-
: this.internalValue[0]
430-
this.$emit('input', deepClone(value), this.id)
432+
this.$emit('input', this.getValue(), this.id)
431433

432434
if (this.closeOnSelect) this.deactivate()
433435
}
@@ -451,10 +453,7 @@ module.exports = {
451453

452454
this.internalValue.splice(index, 1)
453455
this.$emit('remove', deepClone(option), this.id)
454-
const value = this.multiple
455-
? this.internalValue
456-
: this.internalValue[0]
457-
this.$emit('input', deepClone(value), this.id)
456+
this.$emit('input', this.getValue(), this.id)
458457
},
459458
/**
460459
* Calls this.removeElement() with the last element
@@ -510,10 +509,7 @@ module.exports = {
510509
} else {
511510
this.$el.blur()
512511
}
513-
const value = this.multiple
514-
? this.internalValue
515-
: this.internalValue[0]
516-
this.$emit('close', deepClone(value), this.id)
512+
this.$emit('close', this.getValue(), this.id)
517513
},
518514
/**
519515
* Adjusts the Search property to equal the correct value

0 commit comments

Comments
 (0)