Skip to content

Commit c12573a

Browse files
authored
Merge pull request #22 from kevinkosterr/master
Release
2 parents b4415a5 + 31c9cca commit c12573a

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/fields/input/FieldSelect.vue

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,24 @@
22
<div class="vfg-select">
33
<span v-on-click-outside="() => isOpened = false" class="vfg-select-label" :class="{'text-muted': !selectedNames.length}" @click.prevent="onClickInput">
44
<template v-if="selectedNames.length">
5-
<span v-for="(selectedName, index) in selectedNames" :key="selectedName">
6-
<template v-if="index !== 0">, </template>{{ selectedName }}
5+
<span>
6+
<template v-for="(selectedName, index) in selectedNames" :key="selectedName">
7+
<template v-if="index !== 0">, </template>{{ selectedName }}
8+
</template>
79
</span>
810
</template>
911
<template v-else>{{ field.placeholder || 'Select an option' }}</template>
1012
<span class="vfg-fi vfg-fi-right">
13+
<!-- X-Mark Icon from https://heroicons.com -->
14+
<span v-if="hasValue" @click.prevent="resetSelection">
15+
<svg
16+
xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
17+
stroke-width="1.5"
18+
stroke="currentColor"
19+
>
20+
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18 18 6M6 6l12 12" />
21+
</svg>
22+
</span>
1123
<!-- ChevronDown from https://heroicons.com -->
1224
<svg
1325
xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
@@ -67,6 +79,9 @@ export default {
6779
} else {
6880
return [ this.field.options.find(o => o.value === this.currentModelValue).name ]
6981
}
82+
},
83+
hasValue () {
84+
return this.field.multiple ? this.currentModelValue.length : this.currentModelValue
7085
}
7186
},
7287
methods: {
@@ -77,6 +92,9 @@ export default {
7792
}
7893
this.isOpened = true
7994
},
95+
resetSelection () {
96+
this.$emit('onInput', this.field.multiple ? [] : '')
97+
},
8098
isSelected (option) {
8199
return this.currentModelValue?.includes(option.value) ?? false
82100
},

0 commit comments

Comments
 (0)