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": {
"browser": true,
"node": true,
"es6": true
"es6": true,
"jasmine": true
},
"extends": "standard"
+22 -14
View File
@@ -372,7 +372,7 @@
type: Array,
default () {
return []
},
}
},
/**
@@ -475,7 +475,7 @@
return option[this.label]
}
}
return option;
return option
}
},
@@ -583,7 +583,7 @@
dir: {
type: String,
default: 'auto'
},
}
},
data () {
@@ -614,9 +614,9 @@
*/
mutableValue (val, old) {
if (this.multiple) {
this.onChange ? this.onChange(val) : null
if (this.onChange) this.onChange(val)
} else {
this.onChange && val !== old ? this.onChange(val) : null
if (this.onChange && val !== old) this.onChange(val)
}
},
@@ -700,11 +700,11 @@
if (this.multiple) {
let ref = -1
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
}
})
var index = this.mutableValue.indexOf(ref)
const index = this.mutableValue.indexOf(ref)
this.mutableValue.splice(index, 1)
} else {
this.mutableValue = null
@@ -733,7 +733,8 @@
* @return {void}
*/
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) {
this.$refs.search.blur() // dropdown will close on blur
} else {
@@ -758,8 +759,7 @@
selected = true
} else if (typeof opt === 'object' && opt[this.label] === option) {
selected = true
}
else if (opt === option) {
} else if (opt === option) {
selected = true
}
})
@@ -811,9 +811,17 @@
* @return {this.value}
*/
maybeDeleteValue () {
let value = null
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
},
/**
@@ -903,7 +911,7 @@
*/
searchPlaceholder () {
if (this.isValueEmpty && this.placeholder) {
return this.placeholder;
return this.placeholder
}
},
@@ -945,7 +953,7 @@
return !this.mutableValue.length
}
return true;
return true
},
/**
@@ -961,7 +969,7 @@
return []
}
},
}
}
</script>
+1 -1
View File
@@ -14,7 +14,7 @@ Vue.config.devtools = true
new Vue({
el: '#app',
data: {
placeholder: "placeholder",
placeholder: 'placeholder',
value: null,
options: countries,
ajaxRes: [],
+5 -2
View File
@@ -64,9 +64,12 @@ module.exports = {
*/
toggleLoading (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
}
}
}
+9 -2
View File
@@ -32,6 +32,7 @@ module.exports = {
*/
pixelsToPointerTop () {
let pixelsToPointerTop = 0
if (this.$refs.dropdownMenu) {
for (let i = 0; i < this.typeAheadPointer; i++) {
pixelsToPointerTop += this.$refs.dropdownMenu.children[i].offsetHeight
@@ -75,7 +76,13 @@ module.exports = {
* @returns {*}
*/
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
}
}
}
+3 -3
View File
@@ -47,14 +47,14 @@ module.exports = {
*/
typeAheadSelect () {
if (this.filteredOptions[ this.typeAheadPointer ]) {
this.select( this.filteredOptions[ this.typeAheadPointer ] );
this.select(this.filteredOptions[this.typeAheadPointer])
} else if (this.taggable && this.search.length) {
this.select(this.search)
}
if (this.clearSearchOnSelect) {
this.search = "";
this.search = ''
}
},
}
}
}
+25 -31
View File
@@ -18,7 +18,7 @@ Vue.component('v-select', vSelect)
* @returns {Event}
*/
function trigger (target, event, process) {
var e = document.createEvent('HTMLEvents')
const e = document.createEvent('HTMLEvents')
e.initEvent(event, true, true)
if (process) process(e)
target.dispatchEvent(e)
@@ -33,7 +33,7 @@ function trigger(target, event, process) {
* @returns {Event}
*/
function triggerMouse (target, event, process) {
var e = document.createEvent('MouseEvent')
const e = document.createEvent('MouseEvent')
e.initEvent('event', true, true)
if (process) process(e)
target.dispatchEvent(e)
@@ -48,7 +48,7 @@ function triggerMouse(target, event, process) {
* @returns {Event}
*/
function triggerFocusEvent (target, event, process) {
var e = document.createEvent('FocusEvent')
const e = document.createEvent('FocusEvent')
e.initEvent('event', true, true)
if (process) process(e)
target.dispatchEvent(e)
@@ -71,7 +71,6 @@ function searchSubmit(vm, search = false) {
}
describe('Select.vue', () => {
describe('Selecting values', () => {
it('can accept an array with pre-selected values', () => {
const vm = new Vue({
@@ -131,11 +130,11 @@ describe('Select.vue', () => {
}).$mount()
vm.$children[0].select('foo')
expect(vm.$children[0].mutableValue.length).toEqual(1)
}),
})
it('can deselect an option when multiple is false', () => {
const vm = new Vue({
template: `<div><v-select :value="'foo'"></v-select></div>`,
template: `<div><v-select :value="'foo'"></v-select></div>`
}).$mount()
vm.$children[0].deselect('foo')
expect(vm.$children[0].mutableValue).toEqual(null)
@@ -240,14 +239,14 @@ describe('Select.vue', () => {
expect(vm.value).toEqual('bar')
done()
})
}),
})
it('can check if a string value is selected when the value is an object and multiple is true', () => {
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()
expect(vm.$children[0].isOptionSelected('foo')).toEqual(true)
}),
})
describe('change Event', () => {
it('will trigger the input event when the selection changes', (done) => {
@@ -280,7 +279,6 @@ describe('Select.vue', () => {
expect(vm.foo).toEqual(['foo', 'bar'])
done()
})
})
})
})
@@ -365,7 +363,7 @@ describe('Select.vue', () => {
it('can close the dropdown when the el is clicked', (done) => {
const vm = new Vue({
template: '<div><v-select></v-select></div>',
components: {vSelect},
components: {vSelect}
}).$mount()
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) => {
const vm = new Vue({
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', () => {
const vm = new Vue({
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', () => {
const vm = new Vue({
template: '<div><v-select></v-select></div>',
template: '<div><v-select></v-select></div>'
}).$mount()
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', () => {
const vm = new Vue({
template: '<div><v-select></v-select></div>',
template: '<div><v-select></v-select></div>'
}).$mount()
spyOn(vm.$children[0], '$emit')
@@ -462,7 +458,7 @@ describe('Select.vue', () => {
it('will close the dropdown on escape, if search is empty', (done) => {
const vm = new Vue({
template: '<div><v-select></v-select></div>',
components: {vSelect},
components: {vSelect}
}).$mount()
spyOn(vm.$children[0].$refs.search, 'blur')
@@ -529,7 +525,7 @@ describe('Select.vue', () => {
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)
})
@@ -543,7 +539,7 @@ describe('Select.vue', () => {
}).$mount()
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)
})
@@ -573,7 +569,7 @@ describe('Select.vue', () => {
vm.$children[0].typeAheadPointer = 1
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()
})
@@ -587,7 +583,7 @@ describe('Select.vue', () => {
}).$mount()
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()
})
@@ -624,7 +620,7 @@ describe('Select.vue', () => {
'v-select': Mock({
'../mixins/pointerScroll': {methods}
})
},
}
}).$mount()
spyOn(vm.$children[0], 'scrollTo')
@@ -652,7 +648,7 @@ describe('Select.vue', () => {
'v-select': Mock({
'../mixins/pointerScroll': {methods}
})
},
}
}).$mount()
spyOn(vm.$children[0], 'scrollTo')
@@ -664,7 +660,7 @@ describe('Select.vue', () => {
describe('Measuring pixel distances', () => {
it('should calculate pointerHeight as the offsetHeight of the pointer element if it exists', () => {
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()
// 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', () => {
const vm = new Vue({
template: '<div><v-select :options="options" v-model="value" :multiple="true"></v-select></div>',
components: {vSelect},
@@ -766,7 +761,7 @@ describe('Select.vue', () => {
it('will console.warn when options contain objects without a valid label key', (done) => {
spyOn(console, 'warn')
const vm = new Vue({
template: '<div><v-select :options="[{}]"></v-select></div>',
template: '<div><v-select :options="[{}]"></v-select></div>'
}).$mount()
Vue.nextTick(() => {
expect(console.warn).toHaveBeenCalledWith(
@@ -1038,7 +1033,7 @@ describe('Select.vue', () => {
it('should not allow duplicate tags when using string options', (done) => {
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()
vm.$refs.select.search = 'one'
searchSubmit(vm)
@@ -1057,7 +1052,7 @@ describe('Select.vue', () => {
it('should not allow duplicate tags when using object options', (done) => {
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()
vm.$refs.select.search = 'one'
searchSubmit(vm)
@@ -1072,14 +1067,13 @@ describe('Select.vue', () => {
done()
})
})
})
})
describe('Asynchronous Loading', () => {
it('can toggle the loading class', () => {
const vm = new Vue({
template: '<div><v-select ref="select"></v-select></div>',
template: '<div><v-select ref="select"></v-select></div>'
}).$mount()
vm.$refs.select.toggleLoading()
@@ -1268,7 +1262,7 @@ describe('Select.vue', () => {
}).$mount()
vm.$children[0].open = true
vm.$refs.select.search = "t"
vm.$refs.select.search = 't'
expect(vm.$refs.select.search).toEqual('t')
vm.$children[0].onSearchBlur()
@@ -1289,7 +1283,7 @@ describe('Select.vue', () => {
expect(vm.$refs.select.clearSearchOnSelect).toEqual(false)
vm.$children[0].open = true
vm.$refs.select.search = "t"
vm.$refs.select.search = 't'
expect(vm.$refs.select.search).toEqual('t')
vm.$children[0].onSearchBlur()