handle boolean attributes

pull/1289/head
Rich-Harris 7 years ago
parent 5980f0752c
commit 7c47cc19f7

@ -87,8 +87,12 @@ export function setAttribute(node, attribute, value) {
export function setAttributes(node, attributes) {
for (var key in attributes) {
if (attributes[key] === undefined) removeAttribute(node, key);
else setAttribute(node, key, attributes[key]);
if (key in node) {
node[key] = attributes[key];
} else {
if (attributes[key] === undefined) removeAttribute(node, key);
else setAttribute(node, key, attributes[key]);
}
}
}

@ -0,0 +1,27 @@
export default {
data: {
props: {
disabled: true
}
},
html: `
<button disabled>click me</button>
`,
test(assert, component, target) {
const button = target.querySelector('button');
assert.ok(button.disabled);
component.set({
props: { disabled: false }
});
assert.htmlEqual(
target.innerHTML,
`<button>click me</button>`
);
assert.ok(!button.disabled);
},
};

@ -0,0 +1 @@
<button {{...props}} >click me</button>
Loading…
Cancel
Save