2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-05-17 02:29:37 +03:00
- pull toggleTargets out of `toggleDropdown(e)` and into it's own computed property
- add focus, blur to options slots
This commit is contained in:
Jeff
2019-04-29 11:11:23 -07:00
parent 074c0b6686
commit 62e39357bd
2 changed files with 39 additions and 31 deletions
+3 -3
View File
@@ -1,7 +1,7 @@
<template>
<v-select :options="books" label="title">
<template #selected-option="{author, title}">
<component :is="option" v-bind="{author, title}"/>
<v-select :options="books" label="title" multiple>
<template #selected-option="{author, title, focus}">
<component :is="option" v-bind="{author, title}" @click="focus"/>
</template>
<template #option="{author, title}">
<component :is="option" v-bind="{author, title}"/>
+36 -28
View File
@@ -557,22 +557,7 @@
* @return {void}
*/
toggleDropdown (e) {
const target = e.target;
const toggleTargets = [
this.$el,
this.searchEl,
this.$refs.toggle.$el,
];
if (typeof this.$refs.openIndicator !== 'undefined') {
toggleTargets.push(
this.$refs.openIndicator.$el,
// the line below is a bit gross, but required to support IE11 without adding polyfills
...Array.prototype.slice.call(this.$refs.openIndicator.$el.childNodes),
);
}
if (toggleTargets.indexOf(target) > -1 || target.classList.contains('vs__selected')) {
if (this.toggleTargets.indexOf(e.target) > -1 || e.target.classList.contains('vs__selected')) {
if (this.open) {
this.searchEl.blur(); // dropdown will close on blur
} else {
@@ -686,7 +671,12 @@
* @return {*}
*/
normalizeOptionForSlot (option) {
return (typeof option === 'object') ? option : {[this.label]: option};
const normalized = (typeof option === 'object') ? option : {[this.label]: option};
return {
...normalized,
focus: this.onSearchFocus,
blur: this.onSearchBlur,
};
},
/**
@@ -720,20 +710,20 @@
* @emits {search:blur}
* @return {void}
*/
onSearchBlur() {
onSearchBlur () {
if (this.mousedown && !this.searching) {
this.mousedown = false
this.mousedown = false;
} else {
if (this.clearSearchOnBlur) {
this.search = ''
this.search = '';
}
this.closeSearchOptions()
return
this.closeSearchOptions();
return;
}
// Fixed bug where no-options message could not be closed
if (this.search.length === 0 && this.options.length === 0){
this.closeSearchOptions()
return
if (this.search.length === 0 && this.options.length === 0) {
this.closeSearchOptions();
return;
}
},
@@ -742,9 +732,9 @@
* @emits {search:focus}
* @return {void}
*/
onSearchFocus() {
this.open = true
this.$emit('search:focus')
onSearchFocus () {
this.open = true;
this.$emit('search:focus');
},
/**
@@ -851,6 +841,24 @@
return this.options.concat(this.pushedTags);
},
toggleTargets () {
const toggleTargets = [
this.$el,
this.searchEl,
this.$refs.toggle,
];
if (typeof this.$refs.openIndicator !== 'undefined') {
toggleTargets.push(
this.$refs.openIndicator.$el,
// the line below is a bit gross, but required to support IE11 without adding polyfills
...Array.prototype.slice.call(this.$refs.openIndicator.$el.childNodes),
);
}
return toggleTargets;
},
/**
* Find the search input DOM element.
* @returns {HTMLInputElement}