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
fix: render data-tooltip in portal to prevent clipping in overflow containers (#8813)
Abhishek Yadavcda23e9f1ec6
diff --git a/frontend/src/css/md-tooltip.css b/frontend/src/css/md-tooltip.cssindex 2739ed42ef..1c423676eb 100644--- a/frontend/src/css/md-tooltip.css+++ b/frontend/src/css/md-tooltip.css@@ -3,50 +3,15 @@/*This allows you to create a basic tooltip using the data-tooltip attributee.g. <span data-tooltip="Hello, World!">Hover me</span>++ The tooltip content is rendered via the React Tooltip component (Radix UI portal),+ which prevents clipping inside containers with overflow:hidden.+ See: RenderHTML.tsx -> wrapTooltipTargets*/.markdown {[data-tooltip] {- position: relative;cursor: pointer;text-decoration: underline dotted;}-- [data-tooltip]::before,- [data-tooltip]::after {- visibility: hidden;- opacity: 0;- pointer-events: none;- transition: all 0.2s ease;- position: absolute;- z-index: 1000;- left: 50%;- transform: translateX(-50%);- }-- [data-tooltip]::before {- content: attr(data-tooltip);- bottom: calc(100% + 10px);- padding: 5px 10px;- width: max-content;- max-width: 300px;- border-radius: 6px;- background-color: ;- text-align: center;- line-height: 1.4;- white-space: pre-wrap;-- @apply bg-background text-foreground shadow-md border text-base;- }-- [data-tooltip]:hover::before,- [data-tooltip]:hover::after {- visibility: visible;- opacity: 1;- }-- [data-tooltip]:hover::before {- /* stylelint-disable-next-line unit-allowed-list */- transform: translateX(-50%) translateY(10px);- }}diff --git a/frontend/src/plugins/core/RenderHTML.tsx b/frontend/src/plugins/core/RenderHTML.tsxindex 1c13f08c90..275d9d0e23 100644--- a/frontend/src/plugins/core/RenderHTML.tsx+++ b/frontend/src/plugins/core/RenderHTML.tsx@@ -14,6 +14,7 @@ import React, {} from "react";import { CopyClipboardIcon } from "@/components/icons/copy-icon";import { QueryParamPreservingLink } from "@/components/ui/query-param-preserving-link";+import { Tooltip } from "@/components/ui/tooltip";import { DocHoverTarget } from "@/core/documentation/DocHoverTarget";import { sanitizeHtml, useSanitizeHtml } from "./sanitize";@@ -160,6 +161,21 @@ 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).+const wrapTooltipTargets: TransformFn = (+ reactNode: ReactNode,+ domNode: DOMNode,+): JSX.Element | undefined => {+ if (domNode instanceof Element && domNode.attribs?.["data-tooltip"]) {+ const tooltipContent = domNode.attribs["data-tooltip"];+ return (+ <Tooltip content={tooltipContent}>{reactNode as JSX.Element}</Tooltip>+ );+ }+};+const CopyableCode = ({ children }: { children: ReactNode }) => {const ref = useRef<HTMLDivElement>(null);return (@@ -239,6 +255,7 @@ function parseHtml({addCopyButtonToCodehilite,preserveQueryParamsInAnchorLinks,wrapDocHoverTargets,+ wrapTooltipTargets,removeWrappingBodyTags,removeWrappingHtmlTags,];diff --git a/frontend/src/plugins/core/__test__/RenderHTML.test.ts b/frontend/src/plugins/core/__test__/RenderHTML.test.tsindex 6a4fac2af2..38c868b54a 100644--- a/frontend/src/plugins/core/__test__/RenderHTML.test.ts+++ b/frontend/src/plugins/core/__test__/RenderHTML.test.ts@@ -197,6 +197,51 @@ describe("parseHtml", () => {});});+describe("wrapTooltipTargets", () => {+ test("data-tooltip wraps element in Tooltip component", () => {+ const html = '<span data-tooltip="Hello world">Hover me</span>';+ expect(parseHtml({ html })).toMatchInlineSnapshot(`+ <Tooltip+ content="Hello world"+ >+ <span+ data-tooltip="Hello world"+ >+ Hover me+ </span>+ </Tooltip>+ `);+ });++ test("element without data-tooltip is not wrapped", () => {+ const html = "<span>No tooltip</span>";+ expect(parseHtml({ html })).toMatchInlineSnapshot(`+ <span>+ No tooltip+ </span>+ `);+ });++ test("data-tooltip on nested element wraps only that element", () => {+ const html = '<p>Outer <span data-tooltip="tip">inner</span> text</p>';+ expect(parseHtml({ html })).toMatchInlineSnapshot(`+ <p>+ Outer+ <Tooltip+ content="tip"+ >+ <span+ data-tooltip="tip"+ >+ inner+ </span>+ </Tooltip>+ text+ </p>+ `);+ });+});+describe("parseHtml with < nad >", () => {const html ='thread <unnamed> panicked at "assertion failed: `(left == right)`"';