bug(tooltip): Popover portal does not reset UA border, background, and backdrop when using custom tooltip bodies #168
Describe the bug#
When using @tanstack/charts with portal and a custom React tooltip body (renderTooltipBody), the outer container element renders an unwanted border, white/canvas background, padding, box shadow, and in some browsers a backdrop.
This happens due to two issues in packages/charts-core:
- Missing Popover UA Resets: In
tooltip-portal.ts, whenelement.setAttribute("popover", "manual")is called, modern browsers apply their default User-Agent stylesheet rules for:popover-open(border: 2px solid,background-color: Canvas,padding: 0.25em) and create a::backdroppseudo-element.tooltip-portal.tsonly setsposition: fixed,margin: 0, but does not neutralizeborder,background,outline,padding, or::backdrop. - Hardcoded Inline Card Styles on Custom Tooltips: In
tooltip.ts(createTooltip),tooltipElement.stylehas hardcoded inline styles (background: Canvas,border: 1px solid ...,boxShadow: ...,padding: ...). When a consumer provides their own<ChartTooltip />component viarenderTooltipBody, these high-specificity inline styles leak around the custom card, forcing users to use!importantCSS overrides.
Minimal Reproduction#
import { defineChart, lineY } from "@tanstack/charts";
import { Chart } from "@tanstack/charts/react/tooltip";
import { portal } from "@tanstack/charts/tooltip/portal";
import { tooltip } from "@tanstack/charts/tooltip";
const chart = defineChart({
marks: [lineY(data, { x: "time", y: "value" })],
tooltip: {
portal,
use: tooltip,
},
});
export function TelemetryChart() {
return (
<Chart
definition={chart}
renderTooltipBody={({ points }) => (
// Custom styled tooltip card
<div className="rounded-lg border border-zinc-200 bg-zinc-900 p-2 text-white">
Value: {points[0].yValue}
</div>
)}
/>
);
}
Expected Behavior#
When renderTooltipBody is passed, or when portal uses the HTML Popover API:
- The outer popover wrapper element (
.ts-chart-tooltip) should act as an unstyled positioning anchor without default card borders, canvas backgrounds, or padding. - The popover's
::backdropshould be hidden by default (display: none).
Actual Behavior#
The custom tooltip card is wrapped in a container that displays:
- The browser's native popover border and
Canvasbackground color. - TanStack Charts' default card padding, border, and box-shadow inline styles.
Suggested Fix#
- In
tooltip-portal.ts, reset UA popover styles (border: "none",background: "transparent",padding: "0",outline: "none") and inject a backdrop reset stylesheet. - In
tooltip.ts, resettooltipElement.stylewhencustomis true (renderTooltipBodyis active).
I am opening a PR with this fix.
tannerlinsley closed this
tannerlinsley reopened this
The portal resets and custom-body styling fix are released, and the follow-up in #255 also keeps custom card shadows from getting clipped. That follow-up shipped in 1.3.0 and is included in 1.4.0 too. Thanks @stybo for the report and #169!
Closing this out. Please reopen it or send a fresh reproduction if you still see the problem on 1.4.0.
AI review notes: Verified that the downloaded 1.4.0
@tanstack/chartspackage contains the portal overflow fix and that the release includes #255. The original React example was not rerun in this pass.tannerlinsley closed this
Sign in to join this conversation.
Fixed in 1.1.0 through #184. Custom bodies now own their card styling, and switching back restores the built-in styles. We checked the custom wrapper and native backdrop in Chromium, Firefox, and WebKit. Thanks @stybo for the report and #169.