fix: multi select width bug (#303)

* fix: multi  select width  bug

* style: truncate multi-select values text

---------

Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
Favour Olayinka 2024-02-03 17:14:45 +01:00 committed by GitHub
parent ef83ffcf77
commit 8321bd38db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 6 deletions

View File

@ -5,7 +5,6 @@
<template #label> <template #label>
<slot name="label" /> <slot name="label" />
</template> </template>
<v-select v-model="compVal" <v-select v-model="compVal"
:data="finalOptions" :data="finalOptions"
:label="label" :label="label"
@ -26,14 +25,14 @@
:help-position="helpPosition" :help-position="helpPosition"
@update-options="updateOptions" @update-options="updateOptions"
@update:model-value="updateModelValue"
> >
<template #selected="{option}"> <template #selected="{option}">
<slot name="selected" :option="option" :optionName="getOptionName(option)"> <slot name="selected" :option="option" :optionName="getOptionName(option)">
<template v-if="multiple"> <template v-if="multiple">
<div class="flex items-center truncate mr-6"> <div class="flex items-center truncate mr-6">
<span v-for="(item,index) in option" :key="item" class="truncate"> <span class="truncate">
<span v-if="index!==0">, </span> {{ selectedValues.join(', ') }}
{{ getOptionName(item) }}
</span> </span>
</div> </div>
</template> </template>
@ -104,7 +103,8 @@ export default {
data () { data () {
return { return {
additionalOptions: [] additionalOptions: [],
selectedValues:[],
} }
}, },
@ -121,6 +121,9 @@ export default {
if (option) return option[this.displayKey] if (option) return option[this.displayKey]
return null return null
}, },
updateModelValue(newValues){
this.selectedValues = newValues
},
updateOptions (newItem) { updateOptions (newItem) {
if (newItem) { if (newItem) {
this.additionalOptions.push(newItem) this.additionalOptions.push(newItem)

View File

@ -1,5 +1,5 @@
<template> <template>
<div class="v-select relative" ref="select"> <div class="v-select relative" :class="[{'w-0': multiple, 'min-w-full':multiple}]" ref="select">
<span class="inline-block w-full rounded-md"> <span class="inline-block w-full rounded-md">
<button type="button" aria-haspopup="listbox" aria-expanded="true" aria-labelledby="listbox-label" <button type="button" aria-haspopup="listbox" aria-expanded="true" aria-labelledby="listbox-label"
class="cursor-pointer" class="cursor-pointer"