fix one-way <select> bind with spread (#6512)

pull/6560/head
Tan Li Hau 3 years ago committed by GitHub
parent 0d3e105915
commit 8c66acfa92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -669,10 +669,10 @@ export default class ElementWrapper extends Wrapper {
}
block.chunks.mount.push(b`
if (${data}.multiple) @select_options(${this.var}, ${data}.value);
(${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(${this.var}, ${data}.value);
if (${block.renderer.dirty(Array.from(dependencies))}) (${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');

@ -0,0 +1,25 @@
export default {
async test({ assert, component, target, window }) {
const select = target.querySelector('select');
const [option1, option2] = select.childNodes;
let selections = Array.from(select.selectedOptions);
assert.equal(selections.length, 1);
assert.ok(!selections.includes(option1));
assert.ok(selections.includes(option2));
component.value = 'Hello';
selections = Array.from(select.selectedOptions);
assert.equal(selections.length, 1);
assert.ok(selections.includes(option1));
assert.ok(!selections.includes(option2));
component.spread = { value: 'World' };
selections = Array.from(select.selectedOptions);
assert.equal(selections.length, 1);
assert.ok(!selections.includes(option1));
assert.ok(selections.includes(option2));
}
};

@ -0,0 +1,9 @@
<script>
export let value = 'World';
export let spread = {};
</script>
<select {value} {...spread}>
<option>Hello</option>
<option>World</option>
</select>
Loading…
Cancel
Save