diff --git a/src/compiler/compile/render_dom/wrappers/Element/Binding.ts b/src/compiler/compile/render_dom/wrappers/Element/Binding.ts index e48f3e0030..aa3d097ce3 100644 --- a/src/compiler/compile/render_dom/wrappers/Element/Binding.ts +++ b/src/compiler/compile/render_dom/wrappers/Element/Binding.ts @@ -145,8 +145,8 @@ export default class BindingWrapper { } // model to view - let update_dom = get_dom_updater(parent, this); - let mount_dom = update_dom; + let update_dom = get_dom_updater(parent, this, false); + let mount_dom = get_dom_updater(parent, this, true); // special cases switch (this.node.name) { @@ -234,7 +234,8 @@ export default class BindingWrapper { function get_dom_updater( element: ElementWrapper | InlineComponentWrapper, - binding: BindingWrapper + binding: BindingWrapper, + mounting: boolean ) { const { node } = element; @@ -249,6 +250,7 @@ function get_dom_updater( if (node.name === 'select') { return node.get_static_attribute_value('multiple') === true ? b`@select_options(${element.var}, ${binding.snippet})` : + mounting ? b`@select_option(${element.var}, ${binding.snippet}, true)` : b`@select_option(${element.var}, ${binding.snippet})`; } @@ -439,7 +441,7 @@ function get_value_from_dom( return x`$$value`; } - // + + + + + +

selected: b

+ `, + + test({ assert, component, target }) { + assert.equal(component.selected, 'b'); + const select = target.querySelector('select'); + const options = [...target.querySelectorAll('option')]; + + // option with selected attribute should be selected + assert.equal(select.value, 'b'); + assert.ok(options[1].selected); + } +}; diff --git a/test/runtime/samples/binding-select-initial-value-undefined-2/main.svelte b/test/runtime/samples/binding-select-initial-value-undefined-2/main.svelte new file mode 100644 index 0000000000..0640a9ce27 --- /dev/null +++ b/test/runtime/samples/binding-select-initial-value-undefined-2/main.svelte @@ -0,0 +1,13 @@ + + +

selected: {selected}

+ + + +

selected: {selected}

\ No newline at end of file