Skip to content

Commit a53bf5b

Browse files
authored
Merge pull request sagalbot#167 from sagalbot/mutableloading
Mutableloading
2 parents b3696df + 8a17aef commit a53bf5b

File tree

5 files changed

+47
-5
lines changed

5 files changed

+47
-5
lines changed

dev.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<v-select placeholder="multiple, taggable" multiple taggable :options="options" no-drop></v-select>
3636
<v-select placeholder="multiple, taggable, push-tags" multiple push-tags taggable :options="[{label: 'Foo', value: 'foo'}]"></v-select>
3737
<v-select placeholder="unsearchable" :options="options" :searchable="false"></v-select>
38-
<v-select placeholder="loading" loading></v-select>
38+
<v-select placeholder="search github.." label="full_name" @search="search" :options="ajaxRes"></v-select>
3939
</div>
4040
</body>
4141

src/components/Select.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,7 @@
489489
search: '',
490490
open: false,
491491
mutableValue: null,
492-
mutableOptions: [],
493-
mutableLoading: false
492+
mutableOptions: []
494493
}
495494
},
496495
@@ -766,7 +765,7 @@
766765
* @return {Boolean} True if open
767766
*/
768767
dropdownOpen() {
769-
return this.noDrop ? false : this.open
768+
return this.noDrop ? false : this.open && !this.mutableLoading
770769
},
771770
772771
/**

src/dev.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import Vue from 'vue'
22
import vSelect from './components/Select.vue'
33
import countries from 'docs/data/advanced.js'
4+
import debounce from 'lodash/debounce'
5+
import resource from 'vue-resource'
6+
7+
Vue.use(resource)
48

59
Vue.component('v-select', vSelect)
610

@@ -12,6 +16,19 @@ new Vue({
1216
data: {
1317
placeholder: "placeholder",
1418
value: null,
15-
options: countries
19+
options: countries,
20+
ajaxRes: []
21+
},
22+
methods: {
23+
search(search, loading) {
24+
loading(true)
25+
this.getRepositories(search, loading, this)
26+
},
27+
getRepositories: debounce((search, loading, vm) => {
28+
vm.$http.get(`https://api.github.com/search/repositories?q=${search}`).then(res => {
29+
vm.ajaxRes = res.data.items
30+
loading(false)
31+
})
32+
}, 250)
1633
}
1734
})

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)