From b8fef980b3ecf254e8ea03815cd286a0addf9c3e Mon Sep 17 00:00:00 2001 From: Vladimir Kutepov Date: Thu, 1 Mar 2018 11:26:21 +0700 Subject: [PATCH] Falsey attributes --- hyperapp.d.ts | 4 ++-- src/index.js | 8 +++++++- test/dom.test.js | 7 +++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/hyperapp.d.ts b/hyperapp.d.ts index 672779888..150ea4968 100644 --- a/hyperapp.d.ts +++ b/hyperapp.d.ts @@ -24,7 +24,7 @@ export interface Component { /** * 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 @@ -37,7 +37,7 @@ export type Children = VNode | string | number | null; export function h( nodeName: Component | string, attributes?: Attributes, - ...children: Array, + ...children: Array ): VNode /** @namespace [App] */ diff --git a/src/index.js b/src/index.js index d924ca5c8..cf0845510 100644 --- a/src/index.js +++ b/src/index.js @@ -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) } diff --git a/test/dom.test.js b/test/dom.test.js index 0d75149c1..43808b8a3 100644 --- a/test/dom.test.js +++ b/test/dom.test.js @@ -652,3 +652,10 @@ testVdomToHtml("events", [ html: `` } ]) + +testVdomToHtml("falsey attributes", [ + { + vdom: , + html: `` + } +])