Filter out null / undefined in elements.setAttributes

This commit is contained in:
Albin Larsson 2018-06-15 22:52:19 +02:00
parent d522e40594
commit f1c4752036

View File

@ -42,9 +42,11 @@ export function setAttributes(element, attributes) {
return; return;
} }
Object.entries(attributes).forEach(([key, value]) => { // Assume null and undefined attributes should be left out,
element.setAttribute(key, value); // 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 // Create a DocumentFragment