|
16 | 16 | @mousedown="toggleDropdown($event)"
|
17 | 17 | >
|
18 | 18 | <div ref="selectedOptions" class="vs__selected-options">
|
19 |
| - <slot |
20 |
| - v-for="option in selectedValue" |
21 |
| - name="selected-option-container" |
22 |
| - :option="normalizeOptionForSlot(option)" |
23 |
| - :deselect="deselect" |
24 |
| - :multiple="multiple" |
25 |
| - :disabled="disabled" |
26 |
| - > |
27 |
| - <span :key="getOptionKey(option)" class="vs__selected"> |
28 |
| - <slot |
29 |
| - name="selected-option" |
30 |
| - v-bind="normalizeOptionForSlot(option)" |
31 |
| - > |
32 |
| - {{ getOptionLabel(option) }} |
33 |
| - </slot> |
34 |
| - <button |
35 |
| - v-if="multiple" |
36 |
| - ref="deselectButtons" |
37 |
| - :disabled="disabled" |
38 |
| - type="button" |
39 |
| - class="vs__deselect" |
40 |
| - :title="`Deselect ${getOptionLabel(option)}`" |
41 |
| - :aria-label="`Deselect ${getOptionLabel(option)}`" |
42 |
| - @click="deselect(option)" |
43 |
| - > |
44 |
| - <component :is="childComponents.Deselect" /> |
45 |
| - </button> |
46 |
| - </span> |
47 |
| - </slot> |
| 19 | + <template v-if="multiple"> |
| 20 | + <slot |
| 21 | + v-for="option in selectedValue.slice(0, limit > 0 ? limit : selectedValue.length)" |
| 22 | + name="selected-option-container" |
| 23 | + :option="normalizeOptionForSlot(option)" |
| 24 | + :deselect="deselect" |
| 25 | + :multiple="multiple" |
| 26 | + :disabled="disabled" |
| 27 | + > |
| 28 | + <span :key="getOptionKey(option)" class="vs__selected"> |
| 29 | + <slot |
| 30 | + name="selected-option" |
| 31 | + v-bind="normalizeOptionForSlot(option)" |
| 32 | + > |
| 33 | + {{ getOptionLabel(option) }} |
| 34 | + </slot> |
| 35 | + <button |
| 36 | + v-if="multiple" |
| 37 | + ref="deselectButtons" |
| 38 | + :disabled="disabled" |
| 39 | + type="button" |
| 40 | + class="vs__deselect" |
| 41 | + :title="`Deselect ${getOptionLabel(option)}`" |
| 42 | + :aria-label="`Deselect ${getOptionLabel(option)}`" |
| 43 | + @click="deselect(option)" |
| 44 | + > |
| 45 | + <component :is="childComponents.Deselect" /> |
| 46 | + </button> |
| 47 | + </span> |
| 48 | + </slot> |
48 | 49 |
|
| 50 | + <template v-if="selectedValue.length > limit && limit > 0"> |
| 51 | + <span class="vs__limit-label"> |
| 52 | + <slot |
| 53 | + v-if="$slots.limit" |
| 54 | + name="limit" |
| 55 | + :length="scope.limit.length" |
| 56 | + > |
| 57 | + <template #default="{ length }"> |
| 58 | + {{ selectedValue.length - length }} more |
| 59 | + </template> |
| 60 | + </slot> |
| 61 | + <template v-else> |
| 62 | + {{ selectedValue.length - limit }} more |
| 63 | + </template> |
| 64 | + </span> |
| 65 | + </template> |
| 66 | + </template> |
| 67 | + <template v-else> |
| 68 | + <slot |
| 69 | + v-for="option in selectedValue" |
| 70 | + name="selected-option-container" |
| 71 | + :option="normalizeOptionForSlot(option)" |
| 72 | + :deselect="deselect" |
| 73 | + :multiple="multiple" |
| 74 | + :disabled="disabled" |
| 75 | + > |
| 76 | + <span :key="getOptionKey(option)" class="vs__selected"> |
| 77 | + <slot |
| 78 | + name="selected-option" |
| 79 | + v-bind="normalizeOptionForSlot(option)" |
| 80 | + > |
| 81 | + {{ getOptionLabel(option) }} |
| 82 | + </slot> |
| 83 | + <button |
| 84 | + v-if="multiple" |
| 85 | + ref="deselectButtons" |
| 86 | + :disabled="disabled" |
| 87 | + type="button" |
| 88 | + class="vs__deselect" |
| 89 | + :title="`Deselect ${getOptionLabel(option)}`" |
| 90 | + :aria-label="`Deselect ${getOptionLabel(option)}`" |
| 91 | + @click="deselect(option)" |
| 92 | + > |
| 93 | + <component :is="childComponents.Deselect" /> |
| 94 | + </button> |
| 95 | + </span> |
| 96 | + </slot> |
| 97 | + </template> |
49 | 98 | <slot name="search" v-bind="scope.search">
|
50 | 99 | <input
|
51 | 100 | class="vs__search"
|
@@ -668,6 +717,15 @@ export default {
|
668 | 717 | type: [String, Number],
|
669 | 718 | default: () => uniqueId(),
|
670 | 719 | },
|
| 720 | +
|
| 721 | + /** |
| 722 | + * To limit the visibility with multiple options. |
| 723 | + * @type {Number} |
| 724 | + */ |
| 725 | + limit: { |
| 726 | + type: Number, |
| 727 | + default: 0, |
| 728 | + }, |
671 | 729 | },
|
672 | 730 |
|
673 | 731 | data() {
|
@@ -780,6 +838,9 @@ export default {
|
780 | 838 | spinner: {
|
781 | 839 | loading: this.mutableLoading,
|
782 | 840 | },
|
| 841 | + limit: { |
| 842 | + length: this.selectedValue.length, |
| 843 | + }, |
783 | 844 | noOptions: {
|
784 | 845 | search: this.search,
|
785 | 846 | loading: this.mutableLoading,
|
|
0 commit comments