From f1c4752036f58e01df95c30cc9cba4156a0737cd Mon Sep 17 00:00:00 2001 From: Albin Larsson Date: Fri, 15 Jun 2018 22:52:19 +0200 Subject: [PATCH] Filter out null / undefined in elements.setAttributes --- src/js/utils/elements.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/js/utils/elements.js b/src/js/utils/elements.js index 39b944d2..2d314ed8 100644 --- a/src/js/utils/elements.js +++ b/src/js/utils/elements.js @@ -42,9 +42,11 @@ export function setAttributes(element, attributes) { return; } - Object.entries(attributes).forEach(([key, value]) => { - element.setAttribute(key, value); - }); + // Assume null and undefined attributes should be left out, + // Setting them would otherwise convert them to "null" and "undefined" + Object.entries(attributes) + .filter(([, value]) => !is.nullOrUndefined(value)) + .forEach(([key, value]) => element.setAttribute(key, value)); } // Create a DocumentFragment