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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
don't render data-tooltips for marimo components with tooltips (#9129)
Shahmir Varqha9e2b845d566d
diff --git a/frontend/src/plugins/core/RenderHTML.tsx b/frontend/src/plugins/core/RenderHTML.tsxindex efc6ce46fa..4a37a07d73 100644--- a/frontend/src/plugins/core/RenderHTML.tsx+++ b/frontend/src/plugins/core/RenderHTML.tsx@@ -164,11 +164,20 @@ const wrapDocHoverTargets: TransformFn = (// Wrap elements with data-tooltip attribute in a Tooltip component.// This renders the tooltip in a portal (top layer), fixing clipping inside// containers with overflow:hidden (e.g. grid cells).+//+// Marimo custom elements (marimo-button, etc.) are skipped — they handle+// tooltips via the plugin system inside their Shadow DOM. Wrapping them here+// would create a duplicate tooltip with incorrect positioning and+// un-decoded JSON content (the data-* value is JSON-encoded by the backend).const wrapTooltipTargets: TransformFn = (reactNode: ReactNode,domNode: DOMNode,): JSX.Element | undefined => {if (domNode instanceof Element && domNode.attribs?.["data-tooltip"]) {+ const tagName = domNode.name?.toLowerCase() ?? "";+ if (tagName.startsWith("marimo-")) {+ return undefined;+ }const tooltipContent = domNode.attribs["data-tooltip"];return (<Tooltip content={tooltipContent}>{reactNode as JSX.Element}</Tooltip>diff --git a/frontend/src/plugins/core/__test__/RenderHTML.test.ts b/frontend/src/plugins/core/__test__/RenderHTML.test.tsindex 38c868b54a..adf839a1f7 100644--- a/frontend/src/plugins/core/__test__/RenderHTML.test.ts+++ b/frontend/src/plugins/core/__test__/RenderHTML.test.ts@@ -240,6 +240,33 @@ describe("wrapTooltipTargets", () => {</p>`);});++ test("data-tooltip on marimo custom elements is not wrapped", () => {+ const html =+ '<marimo-button data-tooltip=""Run clicky"">click</marimo-button>';+ expect(parseHtml({ html })).toMatchInlineSnapshot(`+ <marimo-button+ data-tooltip=""Run clicky""+ >+ click+ </marimo-button>+ `);+ });++ test("data-tooltip on non-marimo custom elements is still wrapped", () => {+ const html = '<my-widget data-tooltip="info">content</my-widget>';+ expect(parseHtml({ html })).toMatchInlineSnapshot(`+ <Tooltip+ content="info"+ >+ <my-widget+ data-tooltip="info"+ >+ content+ </my-widget>+ </Tooltip>+ `);+ });});describe("parseHtml with < nad >", () => {diff --git a/marimo/_smoke_tests/tooltips.py b/marimo/_smoke_tests/tooltips.pyindex afb1f469cc..834f85193a 100644--- a/marimo/_smoke_tests/tooltips.py+++ b/marimo/_smoke_tests/tooltips.py@@ -2,25 +2,36 @@import marimo-__generated_with = "0.15.5"+__generated_with = "0.23.0"app = marimo.App(width="medium")@app.celldef _():import marimo as mo+return (mo,)@app.celldef _(mo):- mo.md(- """- # Tooltips+ mo.md("""+ # Tooltips- <span data-tooltip="Hello world!">Hover me</span>- """- )+ ## Markdown tooltips (via data-tooltip attribute)++ <span data-tooltip="Hello world!">Hover me (plain text)</span>+ """)+ return+++def _(mo):+ mo.md("""+ ## Button with tooltip in label++ The label contains a `data-tooltip` span — handled by `wrapTooltipTargets` inside the Shadow DOM.+ """)return@@ -31,7 +42,89 @@ def _(mo):@app.cell-def _():+def _(mo):+ mo.md("""+ ## mo.ui.button with tooltip arg++ Tooltip is handled by the plugin (ButtonPlugin) inside the Shadow DOM.+ Should NOT produce a duplicate tooltip from `wrapTooltipTargets`.+ """)+ return+++def _(mo):+ mo.ui.button(tooltip="Click me!", label="Button with tooltip")+ return+++def _(mo):+ mo.md("""+ ## mo.ui.run_button with tooltip arg+ """)+ return+++def _(mo):+ mo.ui.run_button(tooltip="Run clicky")+ return+++def _(mo):+ mo.md("""+ ## mo.ui.button with keyboard shortcut (no explicit tooltip)++ Should show the shortcut as a tooltip.+ """)+ return+++def _(mo):+ mo.ui.button(label="Save", keyboard_shortcut="Ctrl-S")+ return+++def _(mo):+ mo.md("""+ ## mo.ui.button with both tooltip and keyboard shortcut++ Explicit tooltip takes precedence over the shortcut tooltip.+ """)+ return+++def _(mo):+ mo.ui.button(+ label="Submit",+ tooltip="Submit the form",+ keyboard_shortcut="Ctrl-Enter",+ )+ return+++def _(mo):+ mo.md("""+ ## mo.ui.form with submit/clear button tooltips+ """)+ return+++def _(mo):+ mo.ui.text(label="Name").form(+ submit_button_label="Go",+ submit_button_tooltip="Submit the form",+ show_clear_button=True,+ clear_button_label="Reset",+ clear_button_tooltip="Clear all fields",+ )return