handle undefined input value with spread (#5291)

pull/5316/head
Tan Li Hau 4 years ago committed by GitHub
parent 8adb47401e
commit c752ed3527
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -9,6 +9,7 @@
* Include selector in message of `unused-css-selector` warning ([#5252](https://github.com/sveltejs/svelte/issues/5252))
* Fix using `<Namespaced.Component/>`s in child `{#await}`/`{#each}` contexts ([#5255](https://github.com/sveltejs/svelte/issues/5255))
* Fix using `<svelte:component>` in `{:catch}` ([#5259](https://github.com/sveltejs/svelte/issues/5259))
* Fix setting one-way bound `<input>` `value` to `undefined` when it has spread attributes ([#5270](https://github.com/sveltejs/svelte/issues/5270))
## 3.24.1

@ -725,6 +725,18 @@ export default class ElementWrapper extends Wrapper {
block.chunks.update.push(b`
if (${block.renderer.dirty(Array.from(dependencies))} && ${data}.multiple) @select_options(${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');
if (type === null || type === "" || type === "text" || type === "email" || type === "password") {
block.chunks.mount.push(b`
${this.var}.value = ${data}.value;
`);
block.chunks.update.push(b`
if ('value' in ${data}) {
${this.var}.value = ${data}.value;
}
`);
}
}
}

@ -0,0 +1,12 @@
export default {
async test({ assert, component, target, window }) {
const input = target.querySelector("input");
component.value = undefined;
assert.equal(input.value, "undefined");
component.value = "foobar";
assert.equal(input.value, "foobar");
}
};

@ -0,0 +1,5 @@
<script>
export let value = '';
</script>
<input {value} {...{}} />
Loading…
Cancel
Save