From 511d7c24e65611efaa912b93985cd42d5cea84ba Mon Sep 17 00:00:00 2001 From: metonym Date: Sat, 18 Jun 2022 12:27:27 -0700 Subject: [PATCH] fix(select): do not dispatch "change" event on initial load (#1356) Follow-up to #1353 If `selected` is `undefined` or not provided, the "change" event will be dispatched since the first `SelectItem` value will be set as the default. The "change" event should only be dispatched when the value is actually changed. --- src/Select/Select.svelte | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Select/Select.svelte b/src/Select/Select.svelte index af7cd8bf..dfaf8861 100644 --- a/src/Select/Select.svelte +++ b/src/Select/Select.svelte @@ -108,9 +108,16 @@ selectedValue.set(value); }; + let prevSelected = undefined; + afterUpdate(() => { selected = $selectedValue; - dispatch("change", $selectedValue); + + if (prevSelected !== undefined && selected !== prevSelected) { + dispatch("change", $selectedValue); + } + + prevSelected = selected; }); $: errorId = `error-${id}`;