Skip to content

Commit 21c27a3

Browse files
authored
fix: style attribute (#25)
1 parent 08490cd commit 21c27a3

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

packages/runtime/dom/dom.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,20 @@ export function createElement(node: VNode | VNode[]): Node {
2727
// set the attributes of the dom node
2828
const attributes = node.attributes;
2929
for (const key in attributes) {
30+
const value = attributes[key];
3031
if (key.startsWith("on")) {
3132
const eventName = key.slice(2).toLowerCase();
32-
el.addEventListener(eventName, attributes[key]);
33+
el.addEventListener(eventName, value);
34+
}
35+
if (key === "style") {
36+
for (const styleKey of value) {
37+
const styleValue = value[styleKey];
38+
(el as HTMLElement).style[styleKey] = styleValue;
39+
}
3340
} else {
34-
node.tagName === "Fragment"
35-
? null
36-
: // @ts-ignore
37-
el.setAttribute(camelToDash(key), attributes[key]);
41+
if (!(node.tagName === "Fragment")) {
42+
(el as HTMLElement).setAttribute(camelToDash(key), value);
43+
}
3844
}
3945
}
4046

0 commit comments

Comments
 (0)