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

View File

@ -1,5 +1,5 @@
<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">
<button type="button" aria-haspopup="listbox" aria-expanded="true" aria-labelledby="listbox-label"
class="cursor-pointer"