Skip to content

Commit

Permalink
Falsey attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
frenzzy committed Mar 16, 2018
1 parent cf041a6 commit b8fef98
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions hyperapp.d.ts
Expand Up @@ -24,7 +24,7 @@ export interface Component<Attributes = {}> {
/**
* Possibles children types
*/
export type Children = VNode | string | number | null;
export type Children = VNode | string | number | null

/** The soft way to create a VNode.
* @param name An element name or a Component function
Expand All @@ -37,7 +37,7 @@ export type Children = VNode | string | number | null;
export function h<Attributes>(
nodeName: Component<Attributes> | string,
attributes?: Attributes,
...children: Array<Children | Children[]>,
...children: Array<Children | Children[]>
): VNode<Attributes>

/** @namespace [App] */
Expand Down
8 changes: 7 additions & 1 deletion src/index.js
Expand Up @@ -166,7 +166,13 @@ export function app(state, actions, view, container) {
element.removeEventListener(name, eventListener)
}
} else if (name in element && name !== "list" && !isSvg) {
element[name] = value == null ? "" : value
element[name] =
value == null ||
value === "false" ||
value === "off" ||
value === "no"
? ""
: value
} else if (value != null && value !== false) {
element.setAttribute(name, value)
}
Expand Down
7 changes: 7 additions & 0 deletions test/dom.test.js
Expand Up @@ -652,3 +652,10 @@ testVdomToHtml("events", [
html: `<button id="clicked"></button>`
}
])

testVdomToHtml("falsey attributes", [
{
vdom: <input spellcheck="false" autocomplete="off" translate="no" />,
html: `<input spellcheck="false" autocomplete="off" translate="no">`
}
])

0 comments on commit b8fef98

Please sign in to comment.