Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: support multiline text in data-tooltip attributes (#10851)

Myles Scolnick1e6cd334755f
diff --git a/frontend/src/plugins/core/RenderHTML.tsx b/frontend/src/plugins/core/RenderHTML.tsx
index b97d767dbe..ecb726b053 100644
--- a/frontend/src/plugins/core/RenderHTML.tsx
+++ b/frontend/src/plugins/core/RenderHTML.tsx
@@ -263,9 +263,17 @@ const wrapTooltipTargets: TransformFn = (
return undefined;
}
const tooltipContent = domNode.attribs["data-tooltip"];
- return (
- <Tooltip content={tooltipContent}>{reactNode as JSX.Element}</Tooltip>
- );
+ // Convert literal newlines to <br/> elements so the tooltip renders
+ // multiline content. &#10; is decoded to \n by html-react-parser
+ // before this transform runs.
+ const lines = tooltipContent.split("\n");
+ const content: ReactNode =
+ lines.length === 1
+ ? tooltipContent
+ : lines.flatMap((line, i) =>
+ i === 0 ? [line] : [<br key={i} />, line],
+ );
+ return <Tooltip content={content}>{reactNode as JSX.Element}</Tooltip>;
}
};
diff --git a/frontend/src/plugins/core/__test__/RenderHTML.test.ts b/frontend/src/plugins/core/__test__/RenderHTML.test.ts
index dce040740e..f7c57cd67c 100644
--- a/frontend/src/plugins/core/__test__/RenderHTML.test.ts
+++ b/frontend/src/plugins/core/__test__/RenderHTML.test.ts
@@ -450,6 +450,70 @@ describe("wrapTooltipTargets", () => {
</Tooltip>
`);
});
+
+ test("data-tooltip multiline via &#10; entity renders <br/>", () => {
+ const html =
+ '<span data-tooltip="Line A&#10;Line B&#10;Line C">hover</span>';
+ const result = parseHtml({ html });
+ expect(result).toMatchInlineSnapshot(`
+ <Tooltip
+ content={
+ [
+ "Line A",
+ <br />,
+ "Line B",
+ <br />,
+ "Line C",
+ ]
+ }
+ >
+ <span
+ data-tooltip="Line A
+ Line B
+ Line C"
+ >
+ hover
+ </span>
+ </Tooltip>
+ `);
+ });
+
+ test("data-tooltip multiline via literal \\n renders <br/>", () => {
+ const html = '<span data-tooltip="Line A\nLine B">hover</span>';
+ expect(parseHtml({ html })).toMatchInlineSnapshot(`
+ <Tooltip
+ content={
+ [
+ "Line A",
+ <br />,
+ "Line B",
+ ]
+ }
+ >
+ <span
+ data-tooltip="Line A
+ Line B"
+ >
+ hover
+ </span>
+ </Tooltip>
+ `);
+ });
+
+ test("data-tooltip single line still works as before", () => {
+ const html = '<span data-tooltip="Single line">hover</span>';
+ expect(parseHtml({ html })).toMatchInlineSnapshot(`
+ <Tooltip
+ content="Single line"
+ >
+ <span
+ data-tooltip="Single line"
+ >
+ hover
+ </span>
+ </Tooltip>
+ `);
+ });
});
describe("parseHtml with < nad >", () => {