From c8fada4e0c5137037dff7f90a5af0aca3755196a Mon Sep 17 00:00:00 2001 From: Samuel Lorch Date: Tue, 4 Apr 2023 00:01:02 +0200 Subject: [PATCH] PillBox use Index or option key as modelValue --- client/src/components/inputs/PillBar.vue | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/client/src/components/inputs/PillBar.vue b/client/src/components/inputs/PillBar.vue index 6831494..cc79b7a 100644 --- a/client/src/components/inputs/PillBar.vue +++ b/client/src/components/inputs/PillBar.vue @@ -3,16 +3,29 @@ const props = defineModel<{ options: { name: string, + key: string, icon: Component, - selected: boolean, }[], - modelValue: number, + modelValue: number | string, + useIndex: boolean, }>(); -let { options, modelValue } = $(props); +let { options, modelValue, useIndex } = $(props); + +function setSelection(option: any, index: number){ + if (useIndex) { + modelValue = index + } else { + modelValue = option.key + } +} onMounted(async() => { if (modelValue === undefined) { - modelValue = 0 + if (useIndex) { + modelValue = 0 + } else { + modelValue = options[0].key + } } }); @@ -20,7 +33,7 @@ onMounted(async() => {