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

V3/update list items slot (#799)

* add tests for slots, add normalized function for passing options to slots

* update active class

* update active class
This commit is contained in:
Jeff Sagal
2019-03-23 15:58:50 -07:00
committed by GitHub
parent 3979f98327
commit e4d4b27540
3 changed files with 65 additions and 9 deletions
+14 -4
View File
@@ -9,12 +9,12 @@
<div class="vs__selected-options" ref="selectedOptions">
<slot v-for="option in selectedValue"
name="selected-option-container"
:option="(typeof option === 'object')?option:{[label]: option}"
:option="normalizeOptionForSlot(option)"
:deselect="deselect"
:multiple="multiple"
:disabled="disabled">
<span class="vs__selected" v-bind:key="option.index">
<slot name="selected-option" v-bind="(typeof option === 'object')?option:{[label]: option}">
<slot name="selected-option" v-bind="normalizeOptionForSlot(option)">
{{ getOptionLabel(option) }}
</slot>
<button v-if="multiple" :disabled="disabled" @click="deselect(option)" type="button" class="vs__deselect" aria-label="Deselect option">
@@ -55,11 +55,11 @@
v-for="(option, index) in filteredOptions"
:key="index"
class="vs__dropdown-option"
:class="{ active: isOptionSelected(option), 'vs__dropdown-option--highlight': index === typeAheadPointer }"
:class="{ 'vs__dropdown-option--selected': isOptionSelected(option), 'vs__dropdown-option--highlight': index === typeAheadPointer }"
@mouseover="typeAheadPointer = index"
@mousedown.prevent.stop="select(option)"
>
<slot name="option" v-bind="(typeof option === 'object')?option:{[label]: option}">
<slot name="option" v-bind="normalizeOptionForSlot(option)">
{{ getOptionLabel(option) }}
</slot>
</li>
@@ -700,6 +700,16 @@
})
},
/**
* Ensures that options are always
* passed as objects to scoped slots.
* @param option
* @return {*}
*/
normalizeOptionForSlot (option) {
return (typeof option === 'object') ? option : {[this.label]: option};
},
/**
* If push-tags is true, push the
* given option to `this.pushedTags`.