add dataset option

This commit is contained in:
Miodec 2025-12-25 00:15:12 +01:00
parent 4521dc7301
commit c3484630e2

View file

@ -91,12 +91,18 @@ export function createElementWithUtils<T extends HTMLElement>(
tagName: string,
options?: {
classList?: string[];
dataset?: Record<string, string>;
},
): ElementWithUtils<T> {
const element = document.createElement(tagName) as T;
if (options?.classList !== undefined) {
element.classList.add(...options.classList);
}
if (options?.dataset !== undefined) {
for (const key of Object.keys(options.dataset)) {
element.dataset[key] = options.dataset[key];
}
}
return new ElementWithUtils(element);
}