mirror of
https://github.com/tenrok/vue-select.git
synced 2026-06-07 07:12:23 +03:00
f5e3e25dc0
- change currentSelection to mutableValue - change currentOptions to mutableOptions - change showLoading to mutableLoading - add default onChange function that emits an input event - allows the use of v-model syntax on the component - since spies on props throw warnings because they are now immutable, refactor tests so spies aren't required todo: - update docs - 1 failing test from inject-loader issue
68 lines
1.5 KiB
JavaScript
68 lines
1.5 KiB
JavaScript
module.exports = {
|
|
props: {
|
|
/**
|
|
* Toggles the adding of a 'loading' class to the main
|
|
* .v-select wrapper. Useful to control UI state when
|
|
* results are being processed through AJAX.
|
|
*/
|
|
loading: {
|
|
type: Boolean,
|
|
default: false
|
|
},
|
|
|
|
/**
|
|
* Accept a callback function that will be
|
|
* run when the search text changes.
|
|
*
|
|
* loading() accepts a boolean value, and can
|
|
* be used to toggle a loading class from
|
|
* the onSearch callback.
|
|
*
|
|
* @param {search} String Current search text
|
|
* @param {loading} Function(bool) Toggle loading class
|
|
*/
|
|
onSearch: {
|
|
type: Function,
|
|
default: function(search, loading){}
|
|
},
|
|
|
|
/**
|
|
* The number of milliseconds to wait before
|
|
* invoking this.onSearch(). Used to prevent
|
|
* sending an AJAX request until input is complete.
|
|
*/
|
|
debounce: {
|
|
type: Number,
|
|
default: 0
|
|
}
|
|
},
|
|
|
|
watch: {
|
|
/**
|
|
* If a callback & search text has been provided,
|
|
* invoke the onSearch callback.
|
|
*/
|
|
search() {
|
|
if (this.search.length > 0 && this.onSearch) {
|
|
this.onSearch(this.search, this.toggleLoading)
|
|
}
|
|
},
|
|
},
|
|
|
|
methods: {
|
|
/**
|
|
* Toggle this.loading. Optionally pass a boolean
|
|
* value. If no value is provided, this.loading
|
|
* will be set to the opposite of it's current value.
|
|
* @param toggle Boolean
|
|
* @returns {*}
|
|
*/
|
|
toggleLoading(toggle = null) {
|
|
if (toggle == null) {
|
|
return this.showLoading = !this.showLoading
|
|
}
|
|
return this.showLoading = toggle
|
|
}
|
|
}
|
|
}
|