mirror of https://github.com/n2geoff/um
fix attribute rendering issue
This commit is contained in:
parent
4542580344
commit
247475ef8b
18
src/tag.js
18
src/tag.js
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue