Skip to content

Commit 8afba80

Browse files
committed
Fix rendering
1 parent bccee97 commit 8afba80

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

packages/sdk-components-react/src/xml-node.tsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ export const XmlNode = forwardRef<ElementRef<"div">, Props>(
3838
return createElement(tag, attrProps, children);
3939
}
4040

41-
const isTextChild = Children.toArray(children).every(
42-
(child) => typeof child === "string"
43-
);
41+
const childrenArray = Children.toArray(children);
42+
const isTextChild =
43+
childrenArray.length > 0 &&
44+
childrenArray.every((child) => typeof child === "string");
4445

4546
const elementName = tag
4647
// Must start from letter or underscore
@@ -53,14 +54,21 @@ export const XmlNode = forwardRef<ElementRef<"div">, Props>(
5354
);
5455

5556
return (
56-
<div style={{ display: isTextChild ? "flex" : "contents" }} {...props}>
57-
<div style={{ color: "rgb(16, 23, 233)" }}>
57+
<div style={{ display: isTextChild ? "block" : "block" }} {...props}>
58+
<span style={{ color: "rgb(16, 23, 233)" }}>
5859
&lt;{[elementName, ...attributes].join(" ")}&gt;
59-
</div>
60-
<div ref={ref} style={{ marginLeft: isTextChild ? 0 : "1rem" }}>
61-
{children}
62-
</div>
63-
<div style={{ color: "rgb(16, 23, 233)" }}>&lt;/{elementName}&gt;</div>
60+
</span>
61+
{childrenArray.length > 0 &&
62+
(isTextChild ? (
63+
<span ref={ref}>{children}</span>
64+
) : (
65+
<div ref={ref} style={{ marginLeft: isTextChild ? 0 : "1rem" }}>
66+
{children}
67+
</div>
68+
))}
69+
<span style={{ color: "rgb(16, 23, 233)" }}>
70+
&lt;/{elementName}&gt;
71+
</span>
6472
</div>
6573
);
6674
}

0 commit comments

Comments
 (0)