Skip to content

Commit

Permalink
fix: make sure html element attributes are set
Browse files Browse the repository at this point in the history
  • Loading branch information
yuan-93 committed Jul 28, 2024
1 parent 6f8acd8 commit 449be27
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/utils/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ export function make(
el.classList.add(classNames);
}

if (attributes) {
Object.entries(attributes).forEach(([key, value]) => {
if (!value) return;
el.setAttribute(key, value.toString());
});
for (const attrName in attributes) {
// as any is used to avoid TS error that read-only properties of HTMLElement are not assignable
(el[attrName as keyof HtmlElementAttributes] as any) =
attributes[attrName as keyof HtmlElementAttributes];
}

return el;
Expand Down

0 comments on commit 449be27

Please sign in to comment.