2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-06-16 09:10:33 +03:00

Merge pull request #167 from sagalbot/mutableloading

Mutableloading
This commit is contained in:
Jeff
2017-03-22 18:35:43 -07:00
committed by GitHub
5 changed files with 47 additions and 5 deletions
+1 -1
View File
@@ -35,7 +35,7 @@
<v-select placeholder="multiple, taggable" multiple taggable :options="options" no-drop></v-select> <v-select placeholder="multiple, taggable" multiple taggable :options="options" no-drop></v-select>
<v-select placeholder="multiple, taggable, push-tags" multiple push-tags taggable :options="[{label: 'Foo', value: 'foo'}]"></v-select> <v-select placeholder="multiple, taggable, push-tags" multiple push-tags taggable :options="[{label: 'Foo', value: 'foo'}]"></v-select>
<v-select placeholder="unsearchable" :options="options" :searchable="false"></v-select> <v-select placeholder="unsearchable" :options="options" :searchable="false"></v-select>
<v-select placeholder="loading" loading></v-select> <v-select placeholder="search github.." label="full_name" @search="search" :options="ajaxRes"></v-select>
</div> </div>
</body> </body>
+2 -3
View File
@@ -489,8 +489,7 @@
search: '', search: '',
open: false, open: false,
mutableValue: null, mutableValue: null,
mutableOptions: [], mutableOptions: []
mutableLoading: false
} }
}, },
@@ -766,7 +765,7 @@
* @return {Boolean} True if open * @return {Boolean} True if open
*/ */
dropdownOpen() { dropdownOpen() {
return this.noDrop ? false : this.open return this.noDrop ? false : this.open && !this.mutableLoading
}, },
/** /**
+18 -1
View File
@@ -1,6 +1,10 @@
import Vue from 'vue' import Vue from 'vue'
import vSelect from './components/Select.vue' import vSelect from './components/Select.vue'
import countries from 'docs/data/advanced.js' import countries from 'docs/data/advanced.js'
import debounce from 'lodash/debounce'
import resource from 'vue-resource'
Vue.use(resource)
Vue.component('v-select', vSelect) Vue.component('v-select', vSelect)
@@ -12,6 +16,19 @@ new Vue({
data: { data: {
placeholder: "placeholder", placeholder: "placeholder",
value: null, value: null,
options: countries options: countries,
ajaxRes: []
},
methods: {
search(search, loading) {
loading(true)
this.getRepositories(search, loading, this)
},
getRepositories: debounce((search, loading, vm) => {
vm.$http.get(`https://api.github.com/search/repositories?q=${search}`).then(res => {
vm.ajaxRes = res.data.items
loading(false)
})
}, 250)
} }
}) })
+14
View File
@@ -27,6 +27,12 @@ module.exports = {
} }
}, },
data() {
return {
mutableLoading: false
}
},
watch: { watch: {
/** /**
* If a callback & search text has been provided, * If a callback & search text has been provided,
@@ -38,6 +44,14 @@ module.exports = {
this.$emit('search', this.search, this.toggleLoading) this.$emit('search', this.search, this.toggleLoading)
} }
}, },
/**
* Sync the loading prop with the internal
* mutable loading value.
* @param val
*/
loading(val) {
this.mutableLoading = val
}
}, },
methods: { methods: {
+12
View File
@@ -1058,6 +1058,18 @@ describe('Select.vue', () => {
done() done()
}) })
}) })
it('will sync mutable loading with the loading prop', (done) => {
const vm = new Vue({
template: '<div><v-select ref="select" :loading="loading"></v-select></div>',
data: {loading:false}
}).$mount()
vm.loading = true
Vue.nextTick(() => {
expect(vm.$refs.select.mutableLoading).toEqual(true)
done()
})
})
}) })
describe('Reset on options change', () => { describe('Reset on options change', () => {