dom: h should allow ids and multiple class names (#155311)

This commit is contained in:
João Moreno 2022-07-15 17:27:02 +02:00 committed by GitHub
parent f485d5e987
commit 05d1f4a5ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1788,10 +1788,21 @@ export function h(tag: string, ...args: [] | [attributes: { $: string } & DomNod
children = args[1];
}
const [tagName, className] = tag.split('.');
const match = SELECTOR_REGEX.exec(tag);
if (!match) {
throw new Error('Bad use of h');
}
const tagName = match[1] || 'div';
const el = document.createElement(tagName);
if (className) {
el.className = className;
if (match[3]) {
el.id = match[3];
}
if (match[4]) {
el.className = match[4].replace(/\./g, ' ').trim();
}
const result: Record<string, HTMLElement> = {};