2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-06-04 06:32:23 +03:00

move slot up one level

This commit is contained in:
Jeff
2019-10-30 16:44:58 -07:00
parent c6c8281f6f
commit 642e61c48e
+37 -13
View File
@@ -52,19 +52,13 @@
<transition :name="transition">
<ul ref="dropdownMenu" v-if="dropdownOpen" class="vs__dropdown-menu" role="listbox" @mousedown.prevent="onMousedown" @mouseup="onMouseUp">
<li
role="option"
v-for="(option, index) in filteredOptions"
:key="getOptionKey(option)"
class="vs__dropdown-option"
:class="{ 'vs__dropdown-option--selected': isOptionSelected(option), 'vs__dropdown-option--highlight': index === typeAheadPointer, 'vs__dropdown-option--disabled': !selectable(option) }"
@mouseover="selectable(option) ? typeAheadPointer = index : null"
@mousedown.prevent.stop="selectable(option) ? select(option) : null"
>
<slot name="option" v-bind="normalizeOptionForSlot(option)">
{{ getOptionLabel(option) }}
</slot>
</li>
<slot name="option" v-for="(option, index) in normalizedFilteredOptions">
<li
role="option"
v-bind="getDropdownOptionScope(option, index).attributes"
v-on="getDropdownOptionScope(option, index).events"
>{{ getOptionLabel(option) }}</li>
</slot>
<li v-if="!filteredOptions.length" class="vs__no-options" @mousedown.stop="">
<slot name="no-options">Sorry, no matching options.</slot>
</li>
@@ -299,6 +293,32 @@
}
}
},
getDropdownOptionScope: {
type: Function,
default(option, index) {
return {
option,
attributes: {
key: this.getOptionKey(option),
class: {
'vs__dropdown-option': true,
'vs__dropdown-option--selected': this.isOptionSelected(option),
'vs__dropdown-option--highlight': index === this.typeAheadPointer,
'vs__dropdown-option--disabled': !this.selectable(option),
},
},
events: {
'mouseover': () => this.selectable(option) ? this.typeAheadPointer = index : null,
'mousedown': e => {
e.preventDefault();
e.stopPropagation();
return this.selectable(option) ? this.select(option) : null;
}
},
};
},
},
/**
* Select the current value if selectOnTab is enabled
@@ -1052,6 +1072,10 @@
return options
},
normalizedFilteredOptions() {
return this.filteredOptions.map(option => this.normalizeOptionForSlot(option));
},
/**
* Check if there aren't any options selected.
* @return {Boolean}