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

fix #54 and add regression test, use 2 space indents

This commit is contained in:
Jeff Sagal
2016-06-16 15:00:08 -07:00
parent 6789c2abd5
commit 0a15c00b0c
3 changed files with 588 additions and 554 deletions
+4 -3
View File
@@ -7,7 +7,8 @@ Rather than bringing in jQuery just to use Select2 or Chosen, this Vue.js compon
#### Features #### Features
- **Tagging Support (+v.1.1.0)** - **AJAX Support +v1.2.0**
- Tagging Support **+v.1.1.0**
- No JS Dependencies - No JS Dependencies
- List Filtering/Searching - List Filtering/Searching
- Supports Vuex - Supports Vuex
@@ -17,9 +18,9 @@ Rather than bringing in jQuery just to use Select2 or Chosen, this Vue.js compon
#### Upcoming/In Progress #### Upcoming/In Progress
- ~~Tagging (adding options not present in list, see `taggable` branch)~~ **added in v.1.1.0** - ~~Tagging (adding options not present in list, see `taggable` branch)~~ **+v.1.1.0**
- ~~Asyncronous Option Loading~~ **+v.1.2.0**
- Rich Option Templating - Rich Option Templating
- Asyncronous Option Loading
## Live Examples & Docs ## Live Examples & Docs
[http://sagalbot.github.io/vue-select/](http://sagalbot.github.io/vue-select/) [http://sagalbot.github.io/vue-select/](http://sagalbot.github.io/vue-select/)
+12 -4
View File
@@ -138,15 +138,18 @@
animation: vSelectSpinner 1.1s infinite linear; animation: vSelectSpinner 1.1s infinite linear;
transition: opacity .1s; transition: opacity .1s;
} }
.v-select.loading .spinner { .v-select.loading .spinner {
opacity: 1; opacity: 1;
} }
.v-select .spinner, .v-select .spinner,
.v-select .spinner:after { .v-select .spinner:after {
border-radius: 50%; border-radius: 50%;
width: 5em; width: 5em;
height: 5em; height: 5em;
} }
@-webkit-keyframes vSelectSpinner { @-webkit-keyframes vSelectSpinner {
0% { 0% {
transform: rotate(0deg); transform: rotate(0deg);
@@ -155,6 +158,7 @@
transform: rotate(360deg); transform: rotate(360deg);
} }
} }
@keyframes vSelectSpinner { @keyframes vSelectSpinner {
0% { 0% {
transform: rotate(0deg); transform: rotate(0deg);
@@ -172,7 +176,7 @@
{{ placeholder }} {{ placeholder }}
</span> </span>
<span class="selected-tag" v-for="option in valueAsArray"> <span class="selected-tag" v-for="option in valueAsArray" track-by="$index">
{{ getOptionLabel(option) }} {{ getOptionLabel(option) }}
<button v-if="multiple" @click="select(option)" type="button" class="close"> <button v-if="multiple" @click="select(option)" type="button" class="close">
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
@@ -249,7 +253,9 @@
*/ */
options: { options: {
type: Array, type: Array,
default() { return [] }, default() {
return []
},
}, },
/** /**
@@ -388,7 +394,11 @@
watch: { watch: {
value(val, old) { value(val, old) {
if (this.multiple) {
this.onChange ? this.onChange(val) : null
} else {
this.onChange && val !== old ? this.onChange(val) : null this.onChange && val !== old ? this.onChange(val) : null
}
}, },
options() { options() {
if (!this.taggable) { if (!this.taggable) {
@@ -418,13 +428,11 @@
} }
if (this.multiple) { if (this.multiple) {
if (!this.value) { if (!this.value) {
this.$set('value', [option]) this.$set('value', [option])
} else { } else {
this.value.push(option) this.value.push(option)
} }
} else { } else {
this.value = option this.value = option
} }
+38 -13
View File
@@ -190,32 +190,57 @@ describe('Select.vue', () => {
expect(vm.$children[0].isOptionSelected('one')).toEqual(true) expect(vm.$children[0].isOptionSelected('one')).toEqual(true)
}) })
describe('onChange Callback', () => {
it('can run a callback when the selection changes', (done) => { it('can run a callback when the selection changes', (done) => {
const vm = new Vue({ const vm = new Vue({
template: '<div><v-select :on-change="foo" value="bar" :options="options"></v-select></div>', template: `<div><v-select :value="['foo']" :options="['foo','bar','baz']" :on-change="cb"></v-select></div>`,
components: {vSelect}, components: {vSelect},
data: {
val: null,
options: ['foo', 'bar', 'baz']
},
methods: { methods: {
foo(value) { cb(val) {
this.val = value
} }
} }
}).$mount() }).$mount()
vm.$children[0].select('foo') spyOn(vm.$children[0], 'onChange')
Vue.nextTick(function () {
expect(vm.$get('val')).toEqual('foo')
vm.$children[0].$set('value', 'baz') vm.$children[0].select('bar')
Vue.nextTick(function () {
expect(vm.$get('val')).toEqual('baz') Vue.nextTick(() => {
expect(vm.$children[0].onChange).toHaveBeenCalledWith('bar')
vm.$children[0].select('baz')
Vue.nextTick(() => {
expect(vm.$children[0].onChange).toHaveBeenCalledWith('baz')
done() done()
}) })
}) })
}) })
it('should run onChange when multiple is true and the value changes', (done) => {
const vm = new Vue({
template: `<div><v-select v-ref:select :value="['foo']" :options="['foo','bar','baz']" multiple :on-change="cb"></v-select></div>`,
methods: {
cb(val) {
}
}
}).$mount()
spyOn(vm.$children[0], 'onChange')
vm.$children[0].select('bar')
Vue.nextTick(() => {
expect(vm.$children[0].onChange).toHaveBeenCalledWith(['foo','bar'])
vm.$children[0].select('baz')
Vue.nextTick(() => {
expect(vm.$children[0].onChange).toHaveBeenCalledWith(['foo','bar','baz'])
done()
})
})
})
})
}) })
describe('Toggling Dropdown', () => { describe('Toggling Dropdown', () => {