From 1ea9b9fadf4c6189f60504da492b8e324bf8811e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Pe=CC=81ault?= Date: Tue, 12 Oct 2021 00:03:02 +0200 Subject: [PATCH] Define current Select option from selected option and not default --- src/components/molecules/Select.svelte | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/molecules/Select.svelte b/src/components/molecules/Select.svelte index be4ed53..5bb8d64 100644 --- a/src/components/molecules/Select.svelte +++ b/src/components/molecules/Select.svelte @@ -5,6 +5,7 @@ value: string name: string default?: boolean + selected?: boolean } export let id: string @@ -15,8 +16,9 @@ const dispatch = createEventDispatcher() const defaultOption = options.find(option => option.default) const defaultOptionIndex = options.findIndex(option => option.default) + const selectedOptionIndex = options.findIndex(option => option.selected) - let current: number = defaultOptionIndex + let current: number = selectedOptionIndex let currentOptionEl: HTMLElement $: currentOption = options[current]