From 04eafade57b6bd1f9b55e6a2e26d2357aa2aaec7 Mon Sep 17 00:00:00 2001 From: Theodore Brown Date: Sat, 25 Feb 2023 23:48:28 -0600 Subject: [PATCH] fix: select first enabled option by default when initial value is undefined Fixes an unintended regression introduced in #6170. Resolves #7041 --- src/runtime/internal/dom.ts | 4 +++- .../samples/binding-select-initial-value-undefined/_config.js | 4 +++- .../binding-select-initial-value-undefined/main.svelte | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index 52f1198833c6..e73864069c74 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -557,7 +557,9 @@ export function select_option(select, value) { } } - select.selectedIndex = -1; // no option should be selected + if (value !== undefined) { + select.selectedIndex = -1; // no option should be selected + } } export function select_options(select, value) { diff --git a/test/runtime/samples/binding-select-initial-value-undefined/_config.js b/test/runtime/samples/binding-select-initial-value-undefined/_config.js index 27bac7ef77d7..c95cd44046f6 100644 --- a/test/runtime/samples/binding-select-initial-value-undefined/_config.js +++ b/test/runtime/samples/binding-select-initial-value-undefined/_config.js @@ -5,6 +5,7 @@ export default {

selected: a

+