Skip to content

Commit bae486a

Browse files
committed
- move mutableLoading data property to ajax mixin
- open dropdown only when not loading - add watcher to keep loading synced with mutableLoading
1 parent 4581d73 commit bae486a

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

src/components/Select.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,7 @@
488488
search: '',
489489
open: false,
490490
mutableValue: null,
491-
mutableOptions: [],
492-
mutableLoading: false
491+
mutableOptions: []
493492
}
494493
},
495494
@@ -765,7 +764,7 @@
765764
* @return {Boolean} True if open
766765
*/
767766
dropdownOpen() {
768-
return this.noDrop ? false : this.open
767+
return this.noDrop ? false : this.open && !this.mutableLoading
769768
},
770769
771770
/**

src/mixins/ajax.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ module.exports = {
2727
}
2828
},
2929

30+
data() {
31+
return {
32+
mutableLoading: false
33+
}
34+
},
35+
3036
watch: {
3137
/**
3238
* If a callback & search text has been provided,
@@ -38,6 +44,14 @@ module.exports = {
3844
this.$emit('search', this.search, this.toggleLoading)
3945
}
4046
},
47+
/**
48+
* Sync the loading prop with the internal
49+
* mutable loading value.
50+
* @param val
51+
*/
52+
loading(val) {
53+
this.mutableLoading = val
54+
}
4155
},
4256

4357
methods: {

test/unit/specs/Select.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,18 @@ describe('Select.vue', () => {
10581058
done()
10591059
})
10601060
})
1061+
1062+
it('will sync mutable loading with the loading prop', (done) => {
1063+
const vm = new Vue({
1064+
template: '<div><v-select ref="select" :loading="loading"></v-select></div>',
1065+
data: {loading:false}
1066+
}).$mount()
1067+
vm.loading = true
1068+
Vue.nextTick(() => {
1069+
expect(vm.$refs.select.mutableLoading).toEqual(true)
1070+
done()
1071+
})
1072+
})
10611073
})
10621074

10631075
describe('Reset on options change', () => {

0 commit comments

Comments
 (0)