Skip to content

Commit

Permalink
Fix sveltejs#4803 by changing setAttributes to set value as well as _…
Browse files Browse the repository at this point in the history
…_value
  • Loading branch information
dimfeld committed May 9, 2020
1 parent c743e72 commit 43ac9ae
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/runtime/internal/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ export function set_attributes(node: Element & ElementCSSInlineStyle, attributes
node.removeAttribute(key);
} else if (key === 'style') {
node.style.cssText = attributes[key];
} else if (key === '__value' || descriptors[key] && descriptors[key].set) {
} else if (key === '__value') {
const value = attributes[key];
(node as any).__value = value;
(node as any).value = value;
} else if (descriptors[key] && descriptors[key].set) {
node[key] = attributes[key];
} else {
attr(node, key, attributes[key]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default {
props: {
props: {
'data-foo': 'bar'
}
},

html: `<input data-foo="bar" type="radio" value="abc">`,

async test({ assert, component, target, window }) {
const input = target.querySelector('input');
assert.equal(input.value, 'abc');
assert.equal(input.__value, 'abc');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script>
export let props;
let radioValue;
</script>

<input type="radio" value="abc" {...props} bind:group={radioValue} />
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export default {
// This fails because the test checks for __value being set on the node, which
// bind:group requires to work, but when a spread is used to set `value` on the
// element, the code that also sets `__value` on the node is not triggered.
// This is issue #4808.
skip: true,

props: {
props: {
'data-foo': 'bar',
value: 'abc'
}
},

html: `<input data-foo="bar" type="radio" value="abc">`,

async test({ assert, component, target, window }) {
const input = target.querySelector('input');
assert.equal(input.value, 'abc');
assert.equal(input.__value, 'abc');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script>
export let props;
let radioValue;
</script>

<input type="radio" {...props} bind:group={radioValue} />

0 comments on commit 43ac9ae

Please sign in to comment.