Skip to content

Commit 7c47cc1

Browse files
committed
handle boolean attributes
1 parent 5980f07 commit 7c47cc1

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

src/shared/dom.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,12 @@ export function setAttribute(node, attribute, value) {
8787

8888
export function setAttributes(node, attributes) {
8989
for (var key in attributes) {
90-
if (attributes[key] === undefined) removeAttribute(node, key);
91-
else setAttribute(node, key, attributes[key]);
90+
if (key in node) {
91+
node[key] = attributes[key];
92+
} else {
93+
if (attributes[key] === undefined) removeAttribute(node, key);
94+
else setAttribute(node, key, attributes[key]);
95+
}
9296
}
9397
}
9498

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export default {
2+
data: {
3+
props: {
4+
disabled: true
5+
}
6+
},
7+
8+
html: `
9+
<button disabled>click me</button>
10+
`,
11+
12+
test(assert, component, target) {
13+
const button = target.querySelector('button');
14+
15+
assert.ok(button.disabled);
16+
17+
component.set({
18+
props: { disabled: false }
19+
});
20+
21+
assert.htmlEqual(
22+
target.innerHTML,
23+
`<button>click me</button>`
24+
);
25+
assert.ok(!button.disabled);
26+
},
27+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<button {{...props}} >click me</button>

0 commit comments

Comments
 (0)