Skip to content

Commit 05d1f4a

Browse files
authored
dom: h should allow ids and multiple class names (microsoft#155311)
1 parent f485d5e commit 05d1f4a

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/vs/base/browser/dom.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,10 +1788,21 @@ export function h(tag: string, ...args: [] | [attributes: { $: string } & DomNod
17881788
children = args[1];
17891789
}
17901790

1791-
const [tagName, className] = tag.split('.');
1791+
const match = SELECTOR_REGEX.exec(tag);
1792+
1793+
if (!match) {
1794+
throw new Error('Bad use of h');
1795+
}
1796+
1797+
const tagName = match[1] || 'div';
17921798
const el = document.createElement(tagName);
1793-
if (className) {
1794-
el.className = className;
1799+
1800+
if (match[3]) {
1801+
el.id = match[3];
1802+
}
1803+
1804+
if (match[4]) {
1805+
el.className = match[4].replace(/\./g, ' ').trim();
17951806
}
17961807

17971808
const result: Record<string, HTMLElement> = {};

0 commit comments

Comments
 (0)