Skip to content

Commit

Permalink
[fix] handle undefined select value with spread (#6687)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinyaigeek authored Aug 27, 2021
1 parent 5df60e7 commit fc9241f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compiler/compile/render_dom/wrappers/Element/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ export default class ElementWrapper extends Wrapper {
(${data}.multiple ? @select_options : @select_option)(${this.var}, ${data}.value);
`);
block.chunks.update.push(b`
if (${block.renderer.dirty(Array.from(dependencies))}) (${data}.multiple ? @select_options : @select_option)(${this.var}, ${data}.value);;
if (${block.renderer.dirty(Array.from(dependencies))} && 'value' in ${data}) (${data}.multiple ? @select_options : @select_option)(${this.var}, ${data}.value);;
`);
} else if (this.node.name === 'input' && this.attributes.find(attr => attr.node.name === 'value')) {
const type = this.node.get_static_attribute_value('type');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<script>
export let options = [];
export let value = "";
export let label = "";
</script>

<select bind:value {...$$restProps}>
{#each options as option}
<option>{option}</option>
{/each}
</select>
<p>{label}</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default {
async test({ assert, component, target, window }) {
const select = target.querySelector('select');

assert.equal(select.value, '1');

component.label = 'hoge';

assert.equal(select.value, '1');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script>
import Select from "./Select.svelte";
let value = {
a: "1",
b: "1",
};
const options = ["1", "2", "3"];
export let label = "test";
</script>

<Select bind:value={value.a} {options} label={label} />

0 comments on commit fc9241f

Please sign in to comment.