Skip to content

Commit 0a49f90

Browse files
author
Damian Dulisz
committed
1 parent db46a91 commit 0a49f90

File tree

1 file changed

+54
-42
lines changed

1 file changed

+54
-42
lines changed

src/Multiselect.vue

Lines changed: 54 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -55,49 +55,51 @@
5555
</span>
5656
</div>
5757
<transition name="multiselect">
58-
<ul
59-
:style="{ maxHeight: maxHeight + 'px' }"
60-
ref="list"
58+
<div
59+
class="multiselect__content-wrapper"
6160
v-show="isOpen"
6261
@mousedown.prevent
63-
class="multiselect__content">
64-
<slot name="beforeList"></slot>
65-
<li v-if="multiple && max === internalValue.length">
66-
<span class="multiselect__option">
67-
<slot name="maxElements">Maximum of {{ max }} options selected. First remove a selected option to select another.</slot>
68-
</span>
69-
</li>
70-
<template v-if="!max || internalValue.length < max">
71-
<li class="multiselect__element" v-for="(option, index) of filteredOptions" :key="index">
72-
<span
73-
tabindex="0"
74-
v-if="!(option && option.$isLabel)"
75-
:class="optionHighlight(index, option)"
76-
@mousedown.prevent="select(option)"
77-
@mouseenter="pointerSet(index)"
78-
:data-select="option && option.isTag ? tagPlaceholder : selectLabelText"
79-
:data-selected="selectedLabelText"
80-
:data-deselect="deselectLabelText"
81-
class="multiselect__option">
82-
<slot name="option" :option="option" :search="search">
83-
<span>{{ getOptionLabel(option) }}</span>
84-
</slot>
62+
:style="{ maxHeight: maxHeight + 'px' }"
63+
ref="list">
64+
<ul class="multiselect__content" :style="contentStyle">
65+
<slot name="beforeList"></slot>
66+
<li v-if="multiple && max === internalValue.length">
67+
<span class="multiselect__option">
68+
<slot name="maxElements">Maximum of {{ max }} options selected. First remove a selected option to select another.</slot>
8569
</span>
86-
<span
87-
v-if="option && option.$isLabel"
88-
:class="optionHighlight(index, option)"
89-
class="multiselect__option multiselect__option--disabled">
90-
{{ option.$groupLabel }}
70+
</li>
71+
<template v-if="!max || internalValue.length < max">
72+
<li class="multiselect__element" v-for="(option, index) of filteredOptions" :key="index">
73+
<span
74+
tabindex="0"
75+
v-if="!(option && option.$isLabel)"
76+
:class="optionHighlight(index, option)"
77+
@mousedown.prevent="select(option)"
78+
@mouseenter="pointerSet(index)"
79+
:data-select="option && option.isTag ? tagPlaceholder : selectLabelText"
80+
:data-selected="selectedLabelText"
81+
:data-deselect="deselectLabelText"
82+
class="multiselect__option">
83+
<slot name="option" :option="option" :search="search">
84+
<span>{{ getOptionLabel(option) }}</span>
85+
</slot>
86+
</span>
87+
<span
88+
v-if="option && option.$isLabel"
89+
:class="optionHighlight(index, option)"
90+
class="multiselect__option multiselect__option--disabled">
91+
{{ option.$groupLabel }}
92+
</span>
93+
</li>
94+
</template>
95+
<li v-show="filteredOptions.length === 0 && search && !loading">
96+
<span class="multiselect__option">
97+
<slot name="noResult">No elements found. Consider changing the search query.</slot>
9198
</span>
9299
</li>
93-
</template>
94-
<li v-show="filteredOptions.length === 0 && search && !loading">
95-
<span class="multiselect__option">
96-
<slot name="noResult">No elements found. Consider changing the search query.</slot>
97-
</span>
98-
</li>
99-
<slot name="afterList"></slot>
100-
</ul>
100+
<slot name="afterList"></slot>
101+
</ul>
102+
</div>
101103
</transition>
102104
</div>
103105
</template>
@@ -238,6 +240,11 @@
238240
if (this.multiple && this.value && this.value.length) {
239241
return this.isOpen ? { 'width': 'auto' } : { 'display': 'none' }
240242
}
243+
},
244+
contentStyle () {
245+
return this.options.length
246+
? { 'display': 'inline-block' }
247+
: { 'display': 'block' }
241248
}
242249
}
243250
}
@@ -499,23 +506,28 @@ fieldset[disabled] .multiselect {
499506
display: none;
500507
}
501508
502-
.multiselect__content {
509+
.multiselect__content-wrapper {
503510
position: absolute;
504-
list-style: none;
505511
display: block;
506512
background: #fff;
507513
width: 100%;
508514
max-height: 240px;
509515
overflow: auto;
510-
padding: 0;
511-
margin: 0;
512516
border: 1px solid #E8E8E8;
513517
border-top: none;
514518
border-bottom-left-radius: 5px;
515519
border-bottom-right-radius: 5px;
516520
z-index: 50;
517521
}
518522
523+
.multiselect__content {
524+
list-style: none;
525+
display: inline-block;
526+
padding: 0;
527+
margin: 0;
528+
min-width: 100%;
529+
}
530+
519531
.multiselect--above .multiselect__content {
520532
bottom: 100%;
521533
border-bottom-left-radius: 0;

0 commit comments

Comments
 (0)