forked from galaxyproject/galaxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectBasic.vue
More file actions
45 lines (40 loc) · 1.28 KB
/
SelectBasic.vue
File metadata and controls
45 lines (40 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<template>
<VueMultiselect
class="select-basic"
:allow-empty="multiple"
:close-on-select="!multiple"
:options="options"
:multiple="multiple"
:placeholder="placeholder || 'Select an option'"
:value="selectedValue"
deselect-label=""
label="text"
select-label=""
track-by="id"
@input="onInput" />
</template>
<script setup>
import { computed } from "vue";
import VueMultiselect from "vue-multiselect";
const props = defineProps({
value: { required: false },
multiple: { type: Boolean, default: false },
options: { type: Array, default: () => [] },
placeholder: { type: String, default: null },
});
const emit = defineEmits(["input"]);
const selectedValue = computed(() => {
if (!props.value) {
return props.multiple ? [] : null;
}
if (props.multiple) {
return props.options.filter((opt) => props.value.includes(opt.id));
}
const singleValue = Array.isArray(props.value) ? props.value[0] : props.value;
return props.options.find((opt) => opt.id === singleValue) || null;
});
const onInput = (selected) => {
const outputValue = props.multiple ? selected.map((opt) => opt.id) : selected ? selected.id : null;
emit("input", outputValue);
};
</script>