Merge pull request #445 from MareStare/feat/add-ability-to-pass-children-to-make-el

[Part 8] Add an ability to specify child elements to `makeEl`
This commit is contained in:
liamwhite 2025-03-03 23:10:11 -05:00 committed by GitHub
commit 6f4709e1e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -61,6 +61,7 @@ export function removeEl<E extends HTMLElement>(...elements: E[] | ConcatArray<E
export function makeEl<Tag extends keyof HTMLElementTagNameMap>( export function makeEl<Tag extends keyof HTMLElementTagNameMap>(
tag: Tag, tag: Tag,
attr?: Partial<HTMLElementTagNameMap[Tag]>, attr?: Partial<HTMLElementTagNameMap[Tag]>,
children: HTMLElement[] = [],
): HTMLElementTagNameMap[Tag] { ): HTMLElementTagNameMap[Tag] {
const el = document.createElement(tag); const el = document.createElement(tag);
if (attr) { if (attr) {
@ -71,6 +72,7 @@ export function makeEl<Tag extends keyof HTMLElementTagNameMap>(
} }
} }
} }
el.append(...children);
return el; return el;
} }