Skip to content

Commit 3b04e97

Browse files
this is the correct way to set a boolean attribute to true.
Co-authored-by: MichaelWest22 <michael@latent.nz>
1 parent 222d7dd commit 3b04e97

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/idiomorph.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,8 +737,9 @@ var Idiomorph = (function () {
737737
}
738738
if (newLiveValue) {
739739
if (!ignoreUpdate) {
740-
// TODO: do we really want this? tests say so but it feels wrong
741-
oldElement.setAttribute(attributeName, newLiveValue);
740+
// https://developer.mozilla.org/en-US/docs/Glossary/Boolean/HTML
741+
// this is the correct way to set a boolean attribute to "true"
742+
oldElement.setAttribute(attributeName, "");
742743
}
743744
} else {
744745
if (!ignoreAttribute(attributeName, oldElement, "remove", ctx)) {

test/core.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ describe("Core morphing tests", function () {
427427

428428
let finalSrc = '<input type="checkbox" checked>';
429429
Idiomorph.morph(initial, finalSrc, { morphStyle: "outerHTML" });
430-
initial.outerHTML.should.equal('<input type="checkbox" checked="true">');
430+
initial.outerHTML.should.equal('<input type="checkbox" checked="">');
431431
initial.checked.should.equal(true);
432432
document.body.removeChild(parent);
433433
});
@@ -474,7 +474,7 @@ describe("Core morphing tests", function () {
474474
// is this a problem at all?
475475
parent.innerHTML.should.equal(`
476476
<select>
477-
<option selected="true">0</option>
477+
<option selected="">0</option>
478478
<option>1</option>
479479
</select>
480480
`);
@@ -506,7 +506,7 @@ describe("Core morphing tests", function () {
506506
let finalSrc = `
507507
<select>
508508
<option>0</option>
509-
<option selected="true">1</option>
509+
<option selected="">1</option>
510510
</select>
511511
`;
512512
Idiomorph.morph(parent, finalSrc, { morphStyle: "innerHTML" });

0 commit comments

Comments
 (0)