Skip to content

Commit

Permalink
Boolean attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
frenzzy committed Mar 31, 2018
1 parent 8cb82fa commit 11c99a0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/index.js
Expand Up @@ -184,7 +184,12 @@ export function app(state, actions, view, container) {
} else {
element.removeEventListener(name, eventListener)
}
} else if (name in element && name !== "list" && !isSvg) {
} else if (
name in element &&
name !== "list" &&
!(typeof value === "string" && typeof element[name] === "boolean") &&
!isSvg
) {
element[name] = value == null ? "" : value
} else if (value != null && value !== false) {
element.setAttribute(name, value)
Expand Down
27 changes: 27 additions & 0 deletions test/dom.test.js
Expand Up @@ -652,3 +652,30 @@ testVdomToHtml("events", [
html: `<button id="clicked"></button>`
}
])

testVdomToHtml("boolean attributes", [
{
vdom: (
<main>
<input
checked={true}
spellcheck="true"
autocomplete="on"
translate="yes"
/>
<input
checked={false}
spellcheck="false"
autocomplete="off"
translate="no"
/>
</main>
),
html: `
<main>
<input spellcheck="true" autocomplete="on" translate="yes">
<input spellcheck="false" autocomplete="off" translate="no">
</main>
`
}
])

0 comments on commit 11c99a0

Please sign in to comment.