2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-06-22 10:30:34 +03:00

Fix code style issues

This commit is contained in:
Lexxus
2017-12-29 12:07:15 +02:00
parent a54c4123e9
commit 4bf6c0ce44
7 changed files with 1353 additions and 1340 deletions
+2 -1
View File
@@ -11,7 +11,8 @@
"env": { "env": {
"browser": true, "browser": true,
"node": true, "node": true,
"es6": true "es6": true,
"jasmine": true
}, },
"extends": "standard" "extends": "standard"
+51 -43
View File
@@ -370,9 +370,9 @@
*/ */
options: { options: {
type: Array, type: Array,
default() { default () {
return [] return []
}, }
}, },
/** /**
@@ -469,13 +469,13 @@
*/ */
getOptionLabel: { getOptionLabel: {
type: Function, type: Function,
default(option) { default (option) {
if (typeof option === 'object') { if (typeof option === 'object') {
if (this.label && option[this.label]) { if (this.label && option[this.label]) {
return option[this.label] return option[this.label]
} }
} }
return option; return option
} }
}, },
@@ -538,7 +538,7 @@
*/ */
createOption: { createOption: {
type: Function, type: Function,
default(newOption) { default (newOption) {
if (typeof this.mutableOptions[0] === 'object') { if (typeof this.mutableOptions[0] === 'object') {
newOption = {[this.label]: newOption} newOption = {[this.label]: newOption}
} }
@@ -583,10 +583,10 @@
dir: { dir: {
type: String, type: String,
default: 'auto' default: 'auto'
}, }
}, },
data() { data () {
return { return {
search: '', search: '',
open: false, open: false,
@@ -602,7 +602,7 @@
* @param {mixed} val * @param {mixed} val
* @return {void} * @return {void}
*/ */
value(val) { value (val) {
this.mutableValue = val this.mutableValue = val
}, },
@@ -612,11 +612,11 @@
* @param {string|object} old * @param {string|object} old
* @return {void} * @return {void}
*/ */
mutableValue(val, old) { mutableValue (val, old) {
if (this.multiple) { if (this.multiple) {
this.onChange ? this.onChange(val) : null if (this.onChange) this.onChange(val)
} else { } else {
this.onChange && val !== old ? this.onChange(val) : null if (this.onChange && val !== old) this.onChange(val)
} }
}, },
@@ -626,7 +626,7 @@
* @param {array} val * @param {array} val
* @return {void} * @return {void}
*/ */
options(val) { options (val) {
this.mutableOptions = val this.mutableOptions = val
}, },
@@ -635,7 +635,7 @@
* when mutableOptions change. * when mutableOptions change.
* @return {[type]} [description] * @return {[type]} [description]
*/ */
mutableOptions() { mutableOptions () {
if (!this.taggable && this.resetOnOptionsChange) { if (!this.taggable && this.resetOnOptionsChange) {
this.mutableValue = this.multiple ? [] : null this.mutableValue = this.multiple ? [] : null
} }
@@ -647,7 +647,7 @@
* @param {Boolean} val * @param {Boolean} val
* @return {void} * @return {void}
*/ */
multiple(val) { multiple (val) {
this.mutableValue = val ? [] : null this.mutableValue = val ? [] : null
} }
}, },
@@ -656,7 +656,7 @@
* Clone props into mutable values, * Clone props into mutable values,
* attach any event listeners. * attach any event listeners.
*/ */
created() { created () {
this.mutableValue = this.value this.mutableValue = this.value
this.mutableOptions = this.options.slice(0) this.mutableOptions = this.options.slice(0)
this.mutableLoading = this.loading this.mutableLoading = this.loading
@@ -671,7 +671,7 @@
* @param {Object|String} option * @param {Object|String} option
* @return {void} * @return {void}
*/ */
select(option) { select (option) {
if (this.isOptionSelected(option)) { if (this.isOptionSelected(option)) {
this.deselect(option) this.deselect(option)
} else { } else {
@@ -696,15 +696,15 @@
* @param {Object|String} option * @param {Object|String} option
* @return {void} * @return {void}
*/ */
deselect(option) { deselect (option) {
if (this.multiple) { if (this.multiple) {
let ref = -1 let ref = -1
this.mutableValue.forEach((val) => { this.mutableValue.forEach((val) => {
if (val === option || typeof val === 'object' && val[this.label] === option[this.label]) { if (val === option || (typeof val === 'object' && val[this.label] === option[this.label])) {
ref = val ref = val
} }
}) })
var index = this.mutableValue.indexOf(ref) const index = this.mutableValue.indexOf(ref)
this.mutableValue.splice(index, 1) this.mutableValue.splice(index, 1)
} else { } else {
this.mutableValue = null this.mutableValue = null
@@ -716,7 +716,7 @@
* @param {Object|String} option * @param {Object|String} option
* @return {void} * @return {void}
*/ */
onAfterSelect(option) { onAfterSelect (option) {
if (this.closeOnSelect) { if (this.closeOnSelect) {
this.open = !this.open this.open = !this.open
this.$refs.search.blur() this.$refs.search.blur()
@@ -732,8 +732,9 @@
* @param {Event} e * @param {Event} e
* @return {void} * @return {void}
*/ */
toggleDropdown(e) { toggleDropdown (e) {
if (e.target === this.$refs.openIndicator || e.target === this.$refs.search || e.target === this.$refs.toggle || e.target === this.$el) { if (e.target === this.$refs.openIndicator || e.target === this.$refs.search ||
e.target === this.$refs.toggle || e.target === this.$el) {
if (this.open) { if (this.open) {
this.$refs.search.blur() // dropdown will close on blur this.$refs.search.blur() // dropdown will close on blur
} else { } else {
@@ -750,7 +751,7 @@
* @param {Object|String} option * @param {Object|String} option
* @return {Boolean} True when selected | False otherwise * @return {Boolean} True when selected | False otherwise
*/ */
isOptionSelected(option) { isOptionSelected (option) {
if (this.multiple && this.mutableValue) { if (this.multiple && this.mutableValue) {
let selected = false let selected = false
this.mutableValue.forEach(opt => { this.mutableValue.forEach(opt => {
@@ -758,8 +759,7 @@
selected = true selected = true
} else if (typeof opt === 'object' && opt[this.label] === option) { } else if (typeof opt === 'object' && opt[this.label] === option) {
selected = true selected = true
} } else if (opt === option) {
else if (opt === option) {
selected = true selected = true
} }
}) })
@@ -774,7 +774,7 @@
* Otherwise, blur the search input to close the dropdown. * Otherwise, blur the search input to close the dropdown.
* @return {void} * @return {void}
*/ */
onEscape() { onEscape () {
if (!this.search.length) { if (!this.search.length) {
this.$refs.search.blur() this.$refs.search.blur()
} else { } else {
@@ -787,7 +787,7 @@
* @emits {search:blur} * @emits {search:blur}
* @return {void} * @return {void}
*/ */
onSearchBlur() { onSearchBlur () {
if (this.clearSearchOnBlur) { if (this.clearSearchOnBlur) {
this.search = '' this.search = ''
} }
@@ -800,7 +800,7 @@
* @emits {search:focus} * @emits {search:focus}
* @return {void} * @return {void}
*/ */
onSearchFocus() { onSearchFocus () {
this.open = true this.open = true
this.$emit('search:focus') this.$emit('search:focus')
}, },
@@ -810,10 +810,18 @@
* text in the search input, & there's tags to delete * text in the search input, & there's tags to delete
* @return {this.value} * @return {this.value}
*/ */
maybeDeleteValue() { maybeDeleteValue () {
let value = null
if (!this.$refs.search.value.length && this.mutableValue) { if (!this.$refs.search.value.length && this.mutableValue) {
return this.multiple ? this.mutableValue.pop() : this.mutableValue = null if (this.multiple) {
value = this.mutableValue.pop()
} else {
value = this.mutableValue = null
} }
}
return value
}, },
/** /**
@@ -823,7 +831,7 @@
* @param {Object || String} option * @param {Object || String} option
* @return {boolean} * @return {boolean}
*/ */
optionExists(option) { optionExists (option) {
let exists = false let exists = false
this.mutableOptions.forEach(opt => { this.mutableOptions.forEach(opt => {
@@ -844,7 +852,7 @@
* @param {Object || String} option * @param {Object || String} option
* @return {void} * @return {void}
*/ */
maybePushTag(option) { maybePushTag (option) {
if (this.pushTags) { if (this.pushTags) {
this.mutableOptions.push(option) this.mutableOptions.push(option)
} }
@@ -857,7 +865,7 @@
* Classes to be output on .dropdown * Classes to be output on .dropdown
* @return {Object} * @return {Object}
*/ */
dropdownClasses() { dropdownClasses () {
return { return {
open: this.dropdownOpen, open: this.dropdownOpen,
single: !this.multiple, single: !this.multiple,
@@ -874,7 +882,7 @@
* If search text should clear on blur * If search text should clear on blur
* @return {Boolean} True when single and clearSearchOnSelect * @return {Boolean} True when single and clearSearchOnSelect
*/ */
clearSearchOnBlur() { clearSearchOnBlur () {
return this.clearSearchOnSelect && !this.multiple return this.clearSearchOnSelect && !this.multiple
}, },
@@ -883,7 +891,7 @@
* search input * search input
* @return {Boolean} True if non empty value * @return {Boolean} True if non empty value
*/ */
searching() { searching () {
return !!this.search return !!this.search
}, },
@@ -892,7 +900,7 @@
* dropdown menu. * dropdown menu.
* @return {Boolean} True if open * @return {Boolean} True if open
*/ */
dropdownOpen() { dropdownOpen () {
return this.noDrop ? false : this.open && !this.mutableLoading return this.noDrop ? false : this.open && !this.mutableLoading
}, },
@@ -901,9 +909,9 @@
* & there is no value selected. * & there is no value selected.
* @return {String} Placeholder text * @return {String} Placeholder text
*/ */
searchPlaceholder() { searchPlaceholder () {
if (this.isValueEmpty && this.placeholder) { if (this.isValueEmpty && this.placeholder) {
return this.placeholder; return this.placeholder
} }
}, },
@@ -915,7 +923,7 @@
* *
* @return {array} * @return {array}
*/ */
filteredOptions() { filteredOptions () {
if (!this.filterable && !this.taggable) { if (!this.filterable && !this.taggable) {
return this.mutableOptions.slice() return this.mutableOptions.slice()
} }
@@ -937,7 +945,7 @@
* Check if there aren't any options selected. * Check if there aren't any options selected.
* @return {Boolean} * @return {Boolean}
*/ */
isValueEmpty() { isValueEmpty () {
if (this.mutableValue) { if (this.mutableValue) {
if (typeof this.mutableValue === 'object') { if (typeof this.mutableValue === 'object') {
return !Object.keys(this.mutableValue).length return !Object.keys(this.mutableValue).length
@@ -945,14 +953,14 @@
return !this.mutableValue.length return !this.mutableValue.length
} }
return true; return true
}, },
/** /**
* Return the current value in array format. * Return the current value in array format.
* @return {Array} * @return {Array}
*/ */
valueAsArray() { valueAsArray () {
if (this.multiple) { if (this.multiple) {
return this.mutableValue return this.mutableValue
} else if (this.mutableValue) { } else if (this.mutableValue) {
@@ -961,7 +969,7 @@
return [] return []
} }
}, }
} }
</script> </script>
+3 -3
View File
@@ -14,18 +14,18 @@ Vue.config.devtools = true
new Vue({ new Vue({
el: '#app', el: '#app',
data: { data: {
placeholder: "placeholder", placeholder: 'placeholder',
value: null, value: null,
options: countries, options: countries,
ajaxRes: [], ajaxRes: [],
people: [] people: []
}, },
methods: { methods: {
search(search, loading) { search (search, loading) {
loading(true) loading(true)
this.getRepositories(search, loading, this) this.getRepositories(search, loading, this)
}, },
searchPeople(search, loading) { searchPeople (search, loading) {
loading(true) loading(true)
this.getPeople(loading, this) this.getPeople(loading, this)
}, },
+10 -7
View File
@@ -23,11 +23,11 @@ module.exports = {
*/ */
onSearch: { onSearch: {
type: Function, type: Function,
default: function(search, loading){} default: function (search, loading) {}
} }
}, },
data() { data () {
return { return {
mutableLoading: false mutableLoading: false
} }
@@ -38,7 +38,7 @@ module.exports = {
* If a callback & search text has been provided, * If a callback & search text has been provided,
* invoke the onSearch callback. * invoke the onSearch callback.
*/ */
search() { search () {
if (this.search.length > 0) { if (this.search.length > 0) {
this.onSearch(this.search, this.toggleLoading) this.onSearch(this.search, this.toggleLoading)
this.$emit('search', this.search, this.toggleLoading) this.$emit('search', this.search, this.toggleLoading)
@@ -49,7 +49,7 @@ module.exports = {
* mutable loading value. * mutable loading value.
* @param val * @param val
*/ */
loading(val) { loading (val) {
this.mutableLoading = val this.mutableLoading = val
} }
}, },
@@ -62,11 +62,14 @@ module.exports = {
* @param toggle Boolean * @param toggle Boolean
* @returns {*} * @returns {*}
*/ */
toggleLoading(toggle = null) { toggleLoading (toggle = null) {
if (toggle == null) { if (toggle == null) {
return this.mutableLoading = !this.mutableLoading this.mutableLoading = !this.mutableLoading
} else {
this.mutableLoading = toggle
} }
return this.mutableLoading = toggle
return this.mutableLoading
} }
} }
} }
+21 -14
View File
@@ -2,7 +2,7 @@
module.exports = { module.exports = {
watch: { watch: {
typeAheadPointer() { typeAheadPointer () {
this.maybeAdjustScroll() this.maybeAdjustScroll()
} }
}, },
@@ -14,14 +14,14 @@ module.exports = {
* overflow bounds. * overflow bounds.
* @returns {*} * @returns {*}
*/ */
maybeAdjustScroll() { maybeAdjustScroll () {
let pixelsToPointerTop = this.pixelsToPointerTop() let pixelsToPointerTop = this.pixelsToPointerTop()
let pixelsToPointerBottom = this.pixelsToPointerBottom() let pixelsToPointerBottom = this.pixelsToPointerBottom()
if ( pixelsToPointerTop <= this.viewport().top) { if (pixelsToPointerTop <= this.viewport().top) {
return this.scrollTo( pixelsToPointerTop ) return this.scrollTo(pixelsToPointerTop)
} else if (pixelsToPointerBottom >= this.viewport().bottom) { } else if (pixelsToPointerBottom >= this.viewport().bottom) {
return this.scrollTo( this.viewport().top + this.pointerHeight() ) return this.scrollTo(this.viewport().top + this.pointerHeight())
} }
}, },
@@ -30,9 +30,10 @@ module.exports = {
* list to the top of the current pointer element. * list to the top of the current pointer element.
* @returns {number} * @returns {number}
*/ */
pixelsToPointerTop() { pixelsToPointerTop () {
let pixelsToPointerTop = 0 let pixelsToPointerTop = 0
if( this.$refs.dropdownMenu ) {
if (this.$refs.dropdownMenu) {
for (let i = 0; i < this.typeAheadPointer; i++) { for (let i = 0; i < this.typeAheadPointer; i++) {
pixelsToPointerTop += this.$refs.dropdownMenu.children[i].offsetHeight pixelsToPointerTop += this.$refs.dropdownMenu.children[i].offsetHeight
} }
@@ -45,7 +46,7 @@ module.exports = {
* list to the bottom of the current pointer element. * list to the bottom of the current pointer element.
* @returns {*} * @returns {*}
*/ */
pixelsToPointerBottom() { pixelsToPointerBottom () {
return this.pixelsToPointerTop() + this.pointerHeight() return this.pixelsToPointerTop() + this.pointerHeight()
}, },
@@ -53,7 +54,7 @@ module.exports = {
* The offsetHeight of the current pointer element. * The offsetHeight of the current pointer element.
* @returns {number} * @returns {number}
*/ */
pointerHeight() { pointerHeight () {
let element = this.$refs.dropdownMenu ? this.$refs.dropdownMenu.children[this.typeAheadPointer] : false let element = this.$refs.dropdownMenu ? this.$refs.dropdownMenu.children[this.typeAheadPointer] : false
return element ? element.offsetHeight : 0 return element ? element.offsetHeight : 0
}, },
@@ -62,9 +63,9 @@ module.exports = {
* The currently viewable portion of the dropdownMenu. * The currently viewable portion of the dropdownMenu.
* @returns {{top: (string|*|number), bottom: *}} * @returns {{top: (string|*|number), bottom: *}}
*/ */
viewport() { viewport () {
return { return {
top: this.$refs.dropdownMenu ? this.$refs.dropdownMenu.scrollTop: 0, top: this.$refs.dropdownMenu ? this.$refs.dropdownMenu.scrollTop : 0,
bottom: this.$refs.dropdownMenu ? this.$refs.dropdownMenu.offsetHeight + this.$refs.dropdownMenu.scrollTop : 0 bottom: this.$refs.dropdownMenu ? this.$refs.dropdownMenu.offsetHeight + this.$refs.dropdownMenu.scrollTop : 0
} }
}, },
@@ -74,8 +75,14 @@ module.exports = {
* @param position * @param position
* @returns {*} * @returns {*}
*/ */
scrollTo(position) { scrollTo (position) {
return this.$refs.dropdownMenu ? this.$refs.dropdownMenu.scrollTop = position : null let result = null
},
if (this.$refs.dropdownMenu) {
result = this.$refs.dropdownMenu.scrollTop = position
}
return result
}
} }
} }
+13 -13
View File
@@ -1,12 +1,12 @@
module.exports = { module.exports = {
data() { data () {
return { return {
typeAheadPointer: -1 typeAheadPointer: -1
} }
}, },
watch: { watch: {
filteredOptions() { filteredOptions () {
this.typeAheadPointer = 0 this.typeAheadPointer = 0
} }
}, },
@@ -17,10 +17,10 @@ module.exports = {
* subtracting the current index by one. * subtracting the current index by one.
* @return {void} * @return {void}
*/ */
typeAheadUp() { typeAheadUp () {
if (this.typeAheadPointer > 0) { if (this.typeAheadPointer > 0) {
this.typeAheadPointer-- this.typeAheadPointer--
if( this.maybeAdjustScroll ) { if (this.maybeAdjustScroll) {
this.maybeAdjustScroll() this.maybeAdjustScroll()
} }
} }
@@ -31,10 +31,10 @@ module.exports = {
* adding the current index by one. * adding the current index by one.
* @return {void} * @return {void}
*/ */
typeAheadDown() { typeAheadDown () {
if (this.typeAheadPointer < this.filteredOptions.length - 1) { if (this.typeAheadPointer < this.filteredOptions.length - 1) {
this.typeAheadPointer++ this.typeAheadPointer++
if( this.maybeAdjustScroll ) { if (this.maybeAdjustScroll) {
this.maybeAdjustScroll() this.maybeAdjustScroll()
} }
} }
@@ -45,16 +45,16 @@ module.exports = {
* Optionally clear the search input on selection. * Optionally clear the search input on selection.
* @return {void} * @return {void}
*/ */
typeAheadSelect() { typeAheadSelect () {
if( this.filteredOptions[ this.typeAheadPointer ] ) { if (this.filteredOptions[ this.typeAheadPointer ]) {
this.select( this.filteredOptions[ this.typeAheadPointer ] ); this.select(this.filteredOptions[this.typeAheadPointer])
} else if (this.taggable && this.search.length){ } else if (this.taggable && this.search.length) {
this.select(this.search) this.select(this.search)
} }
if( this.clearSearchOnSelect ) { if (this.clearSearchOnSelect) {
this.search = ""; this.search = ''
}
} }
},
} }
} }
+49 -55
View File
@@ -17,8 +17,8 @@ Vue.component('v-select', vSelect)
* @param process * @param process
* @returns {Event} * @returns {Event}
*/ */
function trigger(target, event, process) { function trigger (target, event, process) {
var e = document.createEvent('HTMLEvents') const e = document.createEvent('HTMLEvents')
e.initEvent(event, true, true) e.initEvent(event, true, true)
if (process) process(e) if (process) process(e)
target.dispatchEvent(e) target.dispatchEvent(e)
@@ -32,8 +32,8 @@ function trigger(target, event, process) {
* @param process * @param process
* @returns {Event} * @returns {Event}
*/ */
function triggerMouse(target, event, process) { function triggerMouse (target, event, process) {
var e = document.createEvent('MouseEvent') const e = document.createEvent('MouseEvent')
e.initEvent('event', true, true) e.initEvent('event', true, true)
if (process) process(e) if (process) process(e)
target.dispatchEvent(e) target.dispatchEvent(e)
@@ -47,8 +47,8 @@ function triggerMouse(target, event, process) {
* @param process * @param process
* @returns {Event} * @returns {Event}
*/ */
function triggerFocusEvent(target, event, process) { function triggerFocusEvent (target, event, process) {
var e = document.createEvent('FocusEvent') const e = document.createEvent('FocusEvent')
e.initEvent('event', true, true) e.initEvent('event', true, true)
if (process) process(e) if (process) process(e)
target.dispatchEvent(e) target.dispatchEvent(e)
@@ -60,7 +60,7 @@ function triggerFocusEvent(target, event, process) {
* @param vm * @param vm
* @param search * @param search
*/ */
function searchSubmit(vm, search = false) { function searchSubmit (vm, search = false) {
if (search) { if (search) {
vm.$children[0].search = search vm.$children[0].search = search
} }
@@ -71,7 +71,6 @@ function searchSubmit(vm, search = false) {
} }
describe('Select.vue', () => { describe('Select.vue', () => {
describe('Selecting values', () => { describe('Selecting values', () => {
it('can accept an array with pre-selected values', () => { it('can accept an array with pre-selected values', () => {
const vm = new Vue({ const vm = new Vue({
@@ -126,16 +125,16 @@ describe('Select.vue', () => {
template: '<div><v-select :options="options" :value="value" :multiple="true"></v-select></div>', template: '<div><v-select :options="options" :value="value" :multiple="true"></v-select></div>',
data: { data: {
value: ['foo', 'bar'], value: ['foo', 'bar'],
options: ['foo','bar'] options: ['foo', 'bar']
} }
}).$mount() }).$mount()
vm.$children[0].select('foo') vm.$children[0].select('foo')
expect(vm.$children[0].mutableValue.length).toEqual(1) expect(vm.$children[0].mutableValue.length).toEqual(1)
}), })
it('can deselect an option when multiple is false', () => { it('can deselect an option when multiple is false', () => {
const vm = new Vue({ const vm = new Vue({
template: `<div><v-select :value="'foo'"></v-select></div>`, template: `<div><v-select :value="'foo'"></v-select></div>`
}).$mount() }).$mount()
vm.$children[0].deselect('foo') vm.$children[0].deselect('foo')
expect(vm.$children[0].mutableValue).toEqual(null) expect(vm.$children[0].mutableValue).toEqual(null)
@@ -227,7 +226,7 @@ describe('Select.vue', () => {
components: {vSelect}, components: {vSelect},
data: { data: {
value: 'foo', value: 'foo',
options: ['foo','bar','baz'] options: ['foo', 'bar', 'baz']
} }
}).$mount() }).$mount()
@@ -240,14 +239,14 @@ describe('Select.vue', () => {
expect(vm.value).toEqual('bar') expect(vm.value).toEqual('bar')
done() done()
}) })
}), })
it('can check if a string value is selected when the value is an object and multiple is true', () => { it('can check if a string value is selected when the value is an object and multiple is true', () => {
const vm = new Vue({ const vm = new Vue({
template: `<div><v-select multiple :value="[{label: 'foo', value: 'bar'}]"></v-select></div>`, template: `<div><v-select multiple :value="[{label: 'foo', value: 'bar'}]"></v-select></div>`
}).$mount() }).$mount()
expect(vm.$children[0].isOptionSelected('foo')).toEqual(true) expect(vm.$children[0].isOptionSelected('foo')).toEqual(true)
}), })
describe('change Event', () => { describe('change Event', () => {
it('will trigger the input event when the selection changes', (done) => { it('will trigger the input event when the selection changes', (done) => {
@@ -277,10 +276,9 @@ describe('Select.vue', () => {
vm.$refs.select.select('bar') vm.$refs.select.select('bar')
Vue.nextTick(() => { Vue.nextTick(() => {
expect(vm.foo).toEqual(['foo','bar']) expect(vm.foo).toEqual(['foo', 'bar'])
done() done()
}) })
}) })
}) })
}) })
@@ -292,7 +290,7 @@ describe('Select.vue', () => {
data: {value: 'foo'} data: {value: 'foo'}
}).$mount() }).$mount()
vm.$refs.select.search = 'ba' vm.$refs.select.search = 'ba'
expect(vm.$refs.select.filteredOptions).toEqual(['bar','baz']) expect(vm.$refs.select.filteredOptions).toEqual(['bar', 'baz'])
}) })
it('should not filter the array of strings if filterable is false', () => { it('should not filter the array of strings if filterable is false', () => {
@@ -301,7 +299,7 @@ describe('Select.vue', () => {
data: {value: 'foo'} data: {value: 'foo'}
}).$mount() }).$mount()
vm.$refs.select.search = 'ba' vm.$refs.select.search = 'ba'
expect(vm.$refs.select.filteredOptions).toEqual(['foo','bar','baz']) expect(vm.$refs.select.filteredOptions).toEqual(['foo', 'bar', 'baz'])
}) })
it('should filter without case-sensitivity', () => { it('should filter without case-sensitivity', () => {
@@ -310,7 +308,7 @@ describe('Select.vue', () => {
data: {value: 'foo'} data: {value: 'foo'}
}).$mount() }).$mount()
vm.$refs.select.search = 'ba' vm.$refs.select.search = 'ba'
expect(vm.$refs.select.filteredOptions).toEqual(['Bar','Baz']) expect(vm.$refs.select.filteredOptions).toEqual(['Bar', 'Baz'])
}) })
it('can filter an array of objects based on the objects label key', () => { it('can filter an array of objects based on the objects label key', () => {
@@ -365,7 +363,7 @@ describe('Select.vue', () => {
it('can close the dropdown when the el is clicked', (done) => { it('can close the dropdown when the el is clicked', (done) => {
const vm = new Vue({ const vm = new Vue({
template: '<div><v-select></v-select></div>', template: '<div><v-select></v-select></div>',
components: {vSelect}, components: {vSelect}
}).$mount() }).$mount()
spyOn(vm.$children[0].$refs.search, 'blur') spyOn(vm.$children[0].$refs.search, 'blur')
@@ -379,7 +377,6 @@ describe('Select.vue', () => {
}) })
}) })
it('closes the dropdown when an option is selected, multiple is true, and closeOnSelect option is true', (done) => { it('closes the dropdown when an option is selected, multiple is true, and closeOnSelect option is true', (done) => {
const vm = new Vue({ const vm = new Vue({
template: '<div><v-select ref="select" :options="options" multiple :value="value"></v-select></div>', template: '<div><v-select ref="select" :options="options" multiple :value="value"></v-select></div>',
@@ -418,7 +415,6 @@ describe('Select.vue', () => {
}) })
}) })
it('should close the dropdown on search blur', () => { it('should close the dropdown on search blur', () => {
const vm = new Vue({ const vm = new Vue({
template: '<div><v-select :options="options" multiple :value="value"></v-select></div>', template: '<div><v-select :options="options" multiple :value="value"></v-select></div>',
@@ -436,7 +432,7 @@ describe('Select.vue', () => {
it('will close the dropdown and emit the search:blur event from onSearchBlur', () => { it('will close the dropdown and emit the search:blur event from onSearchBlur', () => {
const vm = new Vue({ const vm = new Vue({
template: '<div><v-select></v-select></div>', template: '<div><v-select></v-select></div>'
}).$mount() }).$mount()
spyOn(vm.$children[0], '$emit') spyOn(vm.$children[0], '$emit')
@@ -449,7 +445,7 @@ describe('Select.vue', () => {
it('will open the dropdown and emit the search:focus event from onSearchFocus', () => { it('will open the dropdown and emit the search:focus event from onSearchFocus', () => {
const vm = new Vue({ const vm = new Vue({
template: '<div><v-select></v-select></div>', template: '<div><v-select></v-select></div>'
}).$mount() }).$mount()
spyOn(vm.$children[0], '$emit') spyOn(vm.$children[0], '$emit')
@@ -462,7 +458,7 @@ describe('Select.vue', () => {
it('will close the dropdown on escape, if search is empty', (done) => { it('will close the dropdown on escape, if search is empty', (done) => {
const vm = new Vue({ const vm = new Vue({
template: '<div><v-select></v-select></div>', template: '<div><v-select></v-select></div>',
components: {vSelect}, components: {vSelect}
}).$mount() }).$mount()
spyOn(vm.$children[0].$refs.search, 'blur') spyOn(vm.$children[0].$refs.search, 'blur')
@@ -529,7 +525,7 @@ describe('Select.vue', () => {
vm.$children[0].typeAheadPointer = 1 vm.$children[0].typeAheadPointer = 1
trigger(vm.$children[0].$refs.search, 'keydown', (e) => e.keyCode = 38) trigger(vm.$children[0].$refs.search, 'keydown', (e) => { e.keyCode = 38 })
expect(vm.$children[0].typeAheadPointer).toEqual(0) expect(vm.$children[0].typeAheadPointer).toEqual(0)
}) })
@@ -543,7 +539,7 @@ describe('Select.vue', () => {
}).$mount() }).$mount()
vm.$children[0].typeAheadPointer = 1 vm.$children[0].typeAheadPointer = 1
trigger(vm.$children[0].$refs.search, 'keydown', (e) => e.keyCode = 40) trigger(vm.$children[0].$refs.search, 'keydown', (e) => { e.keyCode = 40 })
expect(vm.$children[0].typeAheadPointer).toEqual(2) expect(vm.$children[0].typeAheadPointer).toEqual(2)
}) })
@@ -573,7 +569,7 @@ describe('Select.vue', () => {
vm.$children[0].typeAheadPointer = 1 vm.$children[0].typeAheadPointer = 1
spyOn(vm.$children[0], 'maybeAdjustScroll') spyOn(vm.$children[0], 'maybeAdjustScroll')
trigger(vm.$children[0].$refs.search, 'keydown', (e) => e.keyCode = 38) trigger(vm.$children[0].$refs.search, 'keydown', (e) => { e.keyCode = 38 })
expect(vm.$children[0].maybeAdjustScroll).toHaveBeenCalled() expect(vm.$children[0].maybeAdjustScroll).toHaveBeenCalled()
}) })
@@ -587,7 +583,7 @@ describe('Select.vue', () => {
}).$mount() }).$mount()
spyOn(vm.$children[0], 'maybeAdjustScroll') spyOn(vm.$children[0], 'maybeAdjustScroll')
trigger(vm.$children[0].$refs.search, 'keydown', (e) => e.keyCode = 40) trigger(vm.$children[0].$refs.search, 'keydown', (e) => { e.keyCode = 40 })
expect(vm.$children[0].maybeAdjustScroll).toHaveBeenCalled() expect(vm.$children[0].maybeAdjustScroll).toHaveBeenCalled()
}) })
@@ -611,10 +607,10 @@ describe('Select.vue', () => {
it('should scroll up if the pointer is above the current viewport bounds', () => { it('should scroll up if the pointer is above the current viewport bounds', () => {
let methods = Object.assign(pointerScroll.methods, { let methods = Object.assign(pointerScroll.methods, {
pixelsToPointerTop() { pixelsToPointerTop () {
return 1 return 1
}, },
viewport() { viewport () {
return {top: 2, bottom: 0} return {top: 2, bottom: 0}
} }
}) })
@@ -624,7 +620,7 @@ describe('Select.vue', () => {
'v-select': Mock({ 'v-select': Mock({
'../mixins/pointerScroll': {methods} '../mixins/pointerScroll': {methods}
}) })
}, }
}).$mount() }).$mount()
spyOn(vm.$children[0], 'scrollTo') spyOn(vm.$children[0], 'scrollTo')
@@ -639,10 +635,10 @@ describe('Select.vue', () => {
*/ */
xit('should scroll down if the pointer is below the current viewport bounds', () => { xit('should scroll down if the pointer is below the current viewport bounds', () => {
let methods = Object.assign(pointerScroll.methods, { let methods = Object.assign(pointerScroll.methods, {
pixelsToPointerBottom() { pixelsToPointerBottom () {
return 2 return 2
}, },
viewport() { viewport () {
return {top: 0, bottom: 1} return {top: 0, bottom: 1}
} }
}) })
@@ -652,7 +648,7 @@ describe('Select.vue', () => {
'v-select': Mock({ 'v-select': Mock({
'../mixins/pointerScroll': {methods} '../mixins/pointerScroll': {methods}
}) })
}, }
}).$mount() }).$mount()
spyOn(vm.$children[0], 'scrollTo') spyOn(vm.$children[0], 'scrollTo')
@@ -664,7 +660,7 @@ describe('Select.vue', () => {
describe('Measuring pixel distances', () => { describe('Measuring pixel distances', () => {
it('should calculate pointerHeight as the offsetHeight of the pointer element if it exists', () => { it('should calculate pointerHeight as the offsetHeight of the pointer element if it exists', () => {
const vm = new Vue({ const vm = new Vue({
template: `<div><v-select :options="['one', 'two', 'three']"></v-select></div>`, template: `<div><v-select :options="['one', 'two', 'three']"></v-select></div>`
}).$mount() }).$mount()
// dropdown must be open for $refs to exist // dropdown must be open for $refs to exist
@@ -719,7 +715,6 @@ describe('Select.vue', () => {
}) })
it('should remove the last item in the value array on delete keypress when multiple is true', () => { it('should remove the last item in the value array on delete keypress when multiple is true', () => {
const vm = new Vue({ const vm = new Vue({
template: '<div><v-select :options="options" v-model="value" :multiple="true"></v-select></div>', template: '<div><v-select :options="options" v-model="value" :multiple="true"></v-select></div>',
components: {vSelect}, components: {vSelect},
@@ -766,7 +761,7 @@ describe('Select.vue', () => {
it('will console.warn when options contain objects without a valid label key', (done) => { it('will console.warn when options contain objects without a valid label key', (done) => {
spyOn(console, 'warn') spyOn(console, 'warn')
const vm = new Vue({ const vm = new Vue({
template: '<div><v-select :options="[{}]"></v-select></div>', template: '<div><v-select :options="[{}]"></v-select></div>'
}).$mount() }).$mount()
Vue.nextTick(() => { Vue.nextTick(() => {
expect(console.warn).toHaveBeenCalledWith( expect(console.warn).toHaveBeenCalledWith(
@@ -1038,7 +1033,7 @@ describe('Select.vue', () => {
it('should not allow duplicate tags when using string options', (done) => { it('should not allow duplicate tags when using string options', (done) => {
const vm = new Vue({ const vm = new Vue({
template: `<div><v-select ref="select" taggable multiple></v-select></div>`, template: `<div><v-select ref="select" taggable multiple></v-select></div>`
}).$mount() }).$mount()
vm.$refs.select.search = 'one' vm.$refs.select.search = 'one'
searchSubmit(vm) searchSubmit(vm)
@@ -1057,7 +1052,7 @@ describe('Select.vue', () => {
it('should not allow duplicate tags when using object options', (done) => { it('should not allow duplicate tags when using object options', (done) => {
const vm = new Vue({ const vm = new Vue({
template: `<div><v-select ref="select" taggable multiple></v-select></div>`, template: `<div><v-select ref="select" taggable multiple></v-select></div>`
}).$mount() }).$mount()
vm.$refs.select.search = 'one' vm.$refs.select.search = 'one'
searchSubmit(vm) searchSubmit(vm)
@@ -1072,14 +1067,13 @@ describe('Select.vue', () => {
done() done()
}) })
}) })
}) })
}) })
describe('Asynchronous Loading', () => { describe('Asynchronous Loading', () => {
it('can toggle the loading class', () => { it('can toggle the loading class', () => {
const vm = new Vue({ const vm = new Vue({
template: '<div><v-select ref="select"></v-select></div>', template: '<div><v-select ref="select"></v-select></div>'
}).$mount() }).$mount()
vm.$refs.select.toggleLoading() vm.$refs.select.toggleLoading()
@@ -1096,7 +1090,7 @@ describe('Select.vue', () => {
called: false called: false
}, },
methods: { methods: {
foo(val) { foo (val) {
this.called = val this.called = val
} }
} }
@@ -1115,8 +1109,8 @@ describe('Select.vue', () => {
template: '<div><v-select ref="select" search="foo" :on-search="foo"></v-select></div>', template: '<div><v-select ref="select" search="foo" :on-search="foo"></v-select></div>',
data: { called: false }, data: { called: false },
methods: { methods: {
foo(val) { foo (val) {
this.called = ! this.called this.called = !this.called
} }
} }
}).$mount() }).$mount()
@@ -1139,7 +1133,7 @@ describe('Select.vue', () => {
called: false called: false
}, },
methods: { methods: {
foo(val) { foo (val) {
this.called = val this.called = val
} }
} }
@@ -1158,8 +1152,8 @@ describe('Select.vue', () => {
template: '<div><v-select ref="select" search="foo" @search="foo"></v-select></div>', template: '<div><v-select ref="select" search="foo" @search="foo"></v-select></div>',
data: { called: false }, data: { called: false },
methods: { methods: {
foo(val) { foo (val) {
this.called = ! this.called this.called = !this.called
} }
} }
}).$mount() }).$mount()
@@ -1179,7 +1173,7 @@ describe('Select.vue', () => {
const vm = new Vue({ const vm = new Vue({
template: '<div><v-select loading ref="select" :on-search="foo"></v-select></div>', template: '<div><v-select loading ref="select" :on-search="foo"></v-select></div>',
methods: { methods: {
foo(search, loading) { foo (search, loading) {
loading(false) loading(false)
} }
} }
@@ -1196,7 +1190,7 @@ describe('Select.vue', () => {
const vm = new Vue({ const vm = new Vue({
template: '<div><v-select loading ref="select" :on-search="foo"></v-select></div>', template: '<div><v-select loading ref="select" :on-search="foo"></v-select></div>',
methods: { methods: {
foo(search, loading) { foo (search, loading) {
loading(true) loading(true)
} }
} }
@@ -1214,7 +1208,7 @@ describe('Select.vue', () => {
it('will sync mutable loading with the loading prop', (done) => { it('will sync mutable loading with the loading prop', (done) => {
const vm = new Vue({ const vm = new Vue({
template: '<div><v-select ref="select" :loading="loading"></v-select></div>', template: '<div><v-select ref="select" :loading="loading"></v-select></div>',
data: {loading:false} data: {loading: false}
}).$mount() }).$mount()
vm.loading = true vm.loading = true
Vue.nextTick(() => { Vue.nextTick(() => {
@@ -1268,7 +1262,7 @@ describe('Select.vue', () => {
}).$mount() }).$mount()
vm.$children[0].open = true vm.$children[0].open = true
vm.$refs.select.search = "t" vm.$refs.select.search = 't'
expect(vm.$refs.select.search).toEqual('t') expect(vm.$refs.select.search).toEqual('t')
vm.$children[0].onSearchBlur() vm.$children[0].onSearchBlur()
@@ -1278,7 +1272,7 @@ describe('Select.vue', () => {
}) })
}) })
it ('should not reset the search input on focus lost when clearSearchOnSelect is false', (done) => { it('should not reset the search input on focus lost when clearSearchOnSelect is false', (done) => {
const vm = new Vue({ const vm = new Vue({
template: '<div><v-select ref="select" :options="options" :value="value" :clear-search-on-select="false"></v-select></div>', template: '<div><v-select ref="select" :options="options" :value="value" :clear-search-on-select="false"></v-select></div>',
data: { data: {
@@ -1289,7 +1283,7 @@ describe('Select.vue', () => {
expect(vm.$refs.select.clearSearchOnSelect).toEqual(false) expect(vm.$refs.select.clearSearchOnSelect).toEqual(false)
vm.$children[0].open = true vm.$children[0].open = true
vm.$refs.select.search = "t" vm.$refs.select.search = 't'
expect(vm.$refs.select.search).toEqual('t') expect(vm.$refs.select.search).toEqual('t')
vm.$children[0].onSearchBlur() vm.$children[0].onSearchBlur()