fix attribute rendering issue

This commit is contained in:
Geoff Doty 2024-07-20 16:20:12 -04:00
parent 4542580344
commit 247475ef8b
1 changed files with 11 additions and 7 deletions

View File

@ -14,15 +14,19 @@ export default function h(tag, ...args) {
// support all scalar values as TextNodes // support all scalar values as TextNodes
const isScalar = (value) => ["boolean", "string", "number"].includes(typeof value); const isScalar = (value) => ["boolean", "string", "number"].includes(typeof value);
args.forEach((arg) => { for(let i = 0; i < args.length; i++) {
if (isScalar(arg)) { if (isScalar(args[i])) {
el.appendChild(document.createTextNode(arg)); el.appendChild(document.createTextNode(args[i]));
} else if (Array.isArray(arg)) { } else if (Array.isArray(args[i])) {
el.append(...arg); el.append(...args[i]);
} else { } else {
Object.assign(el, arg); for(const [k,v] of Object.entries(args[i])) {
// if not both ways, some attributes do not render
el.setAttribute(k, v);
el[k] = v;
}
}
} }
});
return el; return el;
} }