Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] handle undefined select value with spread #6687

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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} />