Skip to content

Commit

Permalink
this is the correct way to set a boolean attribute to true.
Browse files Browse the repository at this point in the history
Co-authored-by: MichaelWest22 <[email protected]>
  • Loading branch information
botandrose-machine and MichaelWest22 committed Jan 26, 2025
1 parent 222d7dd commit 3b04e97
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/idiomorph.js
Original file line number Diff line number Diff line change
Expand Up @@ -737,8 +737,9 @@ var Idiomorph = (function () {
}
if (newLiveValue) {
if (!ignoreUpdate) {
// TODO: do we really want this? tests say so but it feels wrong
oldElement.setAttribute(attributeName, newLiveValue);
// https://developer.mozilla.org/en-US/docs/Glossary/Boolean/HTML
// this is the correct way to set a boolean attribute to "true"
oldElement.setAttribute(attributeName, "");
}
} else {
if (!ignoreAttribute(attributeName, oldElement, "remove", ctx)) {
Expand Down
6 changes: 3 additions & 3 deletions test/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ describe("Core morphing tests", function () {

let finalSrc = '<input type="checkbox" checked>';
Idiomorph.morph(initial, finalSrc, { morphStyle: "outerHTML" });
initial.outerHTML.should.equal('<input type="checkbox" checked="true">');
initial.outerHTML.should.equal('<input type="checkbox" checked="">');
initial.checked.should.equal(true);
document.body.removeChild(parent);
});
Expand Down Expand Up @@ -474,7 +474,7 @@ describe("Core morphing tests", function () {
// is this a problem at all?
parent.innerHTML.should.equal(`
<select>
<option selected="true">0</option>
<option selected="">0</option>
<option>1</option>
</select>
`);
Expand Down Expand Up @@ -506,7 +506,7 @@ describe("Core morphing tests", function () {
let finalSrc = `
<select>
<option>0</option>
<option selected="true">1</option>
<option selected="">1</option>
</select>
`;
Idiomorph.morph(parent, finalSrc, { morphStyle: "innerHTML" });
Expand Down

0 comments on commit 3b04e97

Please sign in to comment.