fix: allow el() to omit attributes when first child is a node or array
This commit is contained in:
1 parent
4ef6892916
commit
0a28865518
1 file changed
+6
@@ -59,6 +59,12 @@ function badge(state) {
|
||||
|
||||
function el(tag, attrs = {}, ...children) {
|
||||
const node = document.createElement(tag);
|
||||
// Allow el("tr", child1, child2, ...): if the 2nd argument is a node or an
|
||||
// array, treat it as the first child instead of an attributes object.
|
||||
if (attrs && (attrs.nodeType === 1 || Array.isArray(attrs))) {
|
||||
children.unshift(attrs);
|
||||
attrs = {};
|
||||
}
|
||||
for (const [k, v] of Object.entries(attrs || {})) {
|
||||
if (k === "class") node.className = v;
|
||||
else if (k === "text") node.textContent = v;
|
||||
|
||||
Reference in new issue
Block a user