From ac45747a1ccf287051f9b4a6b5dbba229f8d2dff Mon Sep 17 00:00:00 2001 From: Arturo Castillo Delgado Date: Fri, 10 Nov 2017 12:58:39 +0100 Subject: [PATCH] Handle numbers in `styles` (#46) * add failing test for passing numbers in styles * handle numbers correctly in styles --- src/patch.js | 2 +- test/vdom.test.js | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/patch.js b/src/patch.js index eaa8138..d81b9af 100644 --- a/src/patch.js +++ b/src/patch.js @@ -55,7 +55,7 @@ function setElementProp(element, name, value, oldValue) { if (name === "key") { } else if (name === "style") { for (var name in merge(oldValue, (value = value || {}))) { - element.style[name] = value[name] || "" + element.style[name] = value[name] != null ? value[name] : "" } } else { try { diff --git a/test/vdom.test.js b/test/vdom.test.js index 206e769..99494c6 100644 --- a/test/vdom.test.js +++ b/test/vdom.test.js @@ -590,10 +590,18 @@ testTrees("styles", [ node: h("div", { style: { color: "blue", float: "left" } }), html: `
` }, + { + node: h("div", { style: { opacity: 1 } }), + html: `
` + }, + { + node: h("div", { style: { opacity: 0 } }), + html: `
` + }, { node: h("div"), html: `
` - } + }, ]) testTrees("update element data", [