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.

improve perf and visual for table header tooltip (#6488)

Shahmir Varqhafe873a71057f
diff --git a/frontend/src/components/data-table/__tests__/columns.test.tsx b/frontend/src/components/data-table/__tests__/columns.test.tsx
index eab423501a..25a932706c 100644
--- a/frontend/src/components/data-table/__tests__/columns.test.tsx
+++ b/frontend/src/components/data-table/__tests__/columns.test.tsx
@@ -2,6 +2,7 @@
import { render } from "@testing-library/react";
import { describe, expect, it, test } from "vitest";
+import { TooltipProvider } from "@/components/ui/tooltip";
import { generateColumns, inferFieldTypes } from "../columns";
import { getMimeValues, isMimeValue, MimeCell } from "../mime-cell";
import type { FieldTypesWithExternalType } from "../types";
@@ -245,6 +246,43 @@ describe("generateColumns", () => {
expect(columns[0].id).toBe("name");
expect(columns[1].id).toBe("age");
});
+
+ it("should render header with tooltip when headerTooltip is provided", () => {
+ const columns = generateColumns({
+ rowHeaders: [],
+ selection: null,
+ fieldTypes,
+ headerTooltip: { name: "Custom Name Tooltip" },
+ });
+
+ // Get the header function for the first column
+ const headerFunction = columns[0].header;
+ expect(headerFunction).toBeTypeOf("function");
+
+ const mockColumn = {
+ id: "name",
+ getCanSort: () => false,
+ getCanFilter: () => false,
+ columnDef: {
+ meta: {
+ dtype: "string",
+ dataType: "string",
+ },
+ },
+ };
+
+ const { container } = render(
+ <TooltipProvider>
+ {/* @ts-expect-error: mock column and header function */}
+ {headerFunction({ column: mockColumn })}
+ </TooltipProvider>,
+ );
+
+ expect(container.textContent).toContain("name");
+ // The tooltip functionality is tested by verifying that the header renders correctly
+ // when headerTooltip is provided.
+ expect(container.firstChild).toBeTruthy();
+ });
});
describe("MimeCell", () => {
diff --git a/frontend/src/components/data-table/__tests__/data-table.test.tsx b/frontend/src/components/data-table/__tests__/data-table.test.tsx
index 894cac9751..30a128c4e9 100644
--- a/frontend/src/components/data-table/__tests__/data-table.test.tsx
+++ b/frontend/src/components/data-table/__tests__/data-table.test.tsx
@@ -95,42 +95,4 @@ describe("DataTable", () => {
expect(rows[1]).toHaveAttribute("title", "Michael Scott");
expect(rows[2]).toHaveAttribute("title", "Jim Halpert");
});
-
- it("applies headerHoverText mapping to column header titles", () => {
- interface RowData {
- id: number;
- first: string;
- last: string;
- }
-
- const testData: RowData[] = [
- { id: 1, first: "Michael", last: "Scott" },
- { id: 2, first: "Jim", last: "Halpert" },
- ];
-
- const columns: Array<ColumnDef<RowData>> = [
- { accessorKey: "first", header: "First" },
- { accessorKey: "last", header: "Last" },
- ];
-
- render(
- <TooltipProvider>
- <DataTable
- data={testData}
- columns={columns}
- selection={null}
- totalRows={2}
- totalColumns={2}
- pagination={false}
- headerTooltip={{ first: "Given name", last: "Family name" }}
- />
- </TooltipProvider>,
- );
-
- // Header row is role="row" as well; get all headers by role="columnheader"
- const headers = screen.getAllByRole("columnheader");
- // Order should correspond to columns array
- expect(headers[0]).toHaveAttribute("title", "Given name");
- expect(headers[1]).toHaveAttribute("title", "Family name");
- });
});
diff --git a/frontend/src/components/data-table/cell-hover-template/feature.ts b/frontend/src/components/data-table/cell-hover-template/feature.ts
index 0beace674d..49ae824804 100644
--- a/frontend/src/components/data-table/cell-hover-template/feature.ts
+++ b/frontend/src/components/data-table/cell-hover-template/feature.ts
@@ -1,4 +1,4 @@
-/* Copyright 2025 Marimo. All rights reserved. */
+/* Copyright 2024 Marimo. All rights reserved. */
"use no memo";
import type { InitialTableState, TableFeature } from "@tanstack/react-table";
diff --git a/frontend/src/components/data-table/cell-hover-template/types.ts b/frontend/src/components/data-table/cell-hover-template/types.ts
index 35363f8379..d360792c9e 100644
--- a/frontend/src/components/data-table/cell-hover-template/types.ts
+++ b/frontend/src/components/data-table/cell-hover-template/types.ts
@@ -1,4 +1,4 @@
-/* Copyright 2025 Marimo. All rights reserved. */
+/* Copyright 2024 Marimo. All rights reserved. */
/* eslint-disable @typescript-eslint/no-empty-interface */
export interface CellHoverTemplateTableState {
diff --git a/frontend/src/components/data-table/column-header.tsx b/frontend/src/components/data-table/column-header.tsx
index da159299fa..d95072652a 100644
--- a/frontend/src/components/data-table/column-header.tsx
+++ b/frontend/src/components/data-table/column-header.tsx
@@ -3,7 +3,7 @@
import type { Column } from "@tanstack/react-table";
import { capitalize } from "lodash-es";
-import { FilterIcon, InfoIcon, MinusIcon, TextIcon, XIcon } from "lucide-react";
+import { FilterIcon, MinusIcon, TextIcon, XIcon } from "lucide-react";
import { useMemo, useRef, useState } from "react";
import { useLocale } from "react-aria";
import {
@@ -67,14 +67,12 @@ interface DataTableColumnHeaderProps<TData, TValue>
extends React.HTMLAttributes<HTMLDivElement> {
column: Column<TData, TValue>;
header: React.ReactNode;
- headerTitle?: string;
calculateTopKRows?: CalculateTopKRows;
}
export const DataTableColumnHeader = <TData, TValue>({
column,
header,
- headerTitle,
className,
calculateTopKRows,
}: DataTableColumnHeaderProps<TData, TValue>) => {
@@ -88,16 +86,7 @@ export const DataTableColumnHeader = <TData, TValue>({
// No sorting or filtering
if (!column.getCanSort() && !column.getCanFilter()) {
- return (
- <div className={cn(className)} title={headerTitle}>
- <span className="flex items-center gap-1">
- {header}
- {headerTitle && (
- <InfoIcon className="h-3 w-3 text-muted-foreground" />
- )}
- </span>
- </div>
- );
+ return <div className={cn(className)}>{header}</div>;
}
const hasFilter = column.getFilterValue() !== undefined;
@@ -113,14 +102,8 @@ export const DataTableColumnHeader = <TData, TValue>({
className,
)}
data-testid="data-table-sort-button"
- title={headerTitle}
>
- <span className="flex-1 flex items-center gap-1">
- {header}
- {headerTitle && (
- <InfoIcon className="h-3 w-3 text-muted-foreground" />
- )}
- </span>
+ <span className="flex-1">{header}</span>
<span
className={cn(
"h-5 py-1 px-1",
diff --git a/frontend/src/components/data-table/columns.tsx b/frontend/src/components/data-table/columns.tsx
index f974b38e90..e95d13335c 100644
--- a/frontend/src/components/data-table/columns.tsx
+++ b/frontend/src/components/data-table/columns.tsx
@@ -17,6 +17,7 @@ import { JsonOutput } from "../editor/output/JsonOutput";
import { Button } from "../ui/button";
import { Checkbox } from "../ui/checkbox";
import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover";
+import { Tooltip } from "../ui/tooltip";
import { DataTableColumnHeader } from "./column-header";
import type { ColumnChartSpecModel } from "./column-summary/chart-spec-model";
import { TableColumnSummary } from "./column-summary/column-summary";
@@ -182,16 +183,30 @@ export function generateColumns<T>({
const headerWithType = (
<div className="flex flex-col">
- <span className="font-bold">{key === "" ? " " : key}</span>
+ <span
+ className={cn(
+ "font-bold",
+ headerTitle && "underline decoration-dotted",
+ )}
+ >
+ {key === "" ? " " : key}
+ </span>
{dtypeHeader}
</div>
);
+ const headerWithTooltip = headerTitle ? (
+ <Tooltip content={headerTitle} delayDuration={300}>
+ {headerWithType}
+ </Tooltip>
+ ) : (
+ headerWithType
+ );
+
const dataTableColumnHeader = (
<DataTableColumnHeader
- header={headerWithType}
+ header={headerWithTooltip}
column={column}
- headerTitle={headerTitle}
calculateTopKRows={calculateTopKRows}
/>
);
diff --git a/frontend/src/components/data-table/data-table.tsx b/frontend/src/components/data-table/data-table.tsx
index 252d3ae702..01038eaa16 100644
--- a/frontend/src/components/data-table/data-table.tsx
+++ b/frontend/src/components/data-table/data-table.tsx
@@ -66,7 +66,6 @@ interface DataTableProps<TData> extends Partial<DownloadActionProps> {
cellSelection?: CellSelectionState;
cellStyling?: CellStyleState | null;
hoverTemplate?: string | null;
- headerTooltip?: Record<string, string> | undefined;
onRowSelectionChange?: OnChangeFn<RowSelectionState>;
onCellSelectionChange?: OnChangeFn<CellSelectionState>;
getRowIds?: GetRowIds;
@@ -108,7 +107,6 @@ const DataTableInternal = <TData,>({
cellSelection,
cellStyling,
hoverTemplate,
- headerTooltip,
paginationState,
setPaginationState,
downloadAs,
@@ -269,7 +267,7 @@ const DataTableInternal = <TData,>({
{showLoadingBar && (
<div className="absolute top-0 left-0 h-[3px] w-1/2 bg-primary animate-slide" />
)}
- {renderTableHeader(table, headerTooltip)}
+ {renderTableHeader(table)}
<CellSelectionProvider>
<DataTableBody
table={table}
diff --git a/frontend/src/components/data-table/renderers.tsx b/frontend/src/components/data-table/renderers.tsx
index de19538923..7bb2062391 100644
--- a/frontend/src/components/data-table/renderers.tsx
+++ b/frontend/src/components/data-table/renderers.tsx
@@ -2,7 +2,6 @@
"use no memo";
import {
- type AccessorKeyColumnDefBase,
type Cell,
type Column,
type ColumnDef,
@@ -27,7 +26,6 @@ import { useScrollIntoViewOnFocus } from "./range-focus/use-scroll-into-view";
export function renderTableHeader<TData>(
table: Table<TData>,
- headerTooltip?: Record<string, string>,
): JSX.Element | null {
if (!table.getRowModel().rows?.length) {
return null;
@@ -37,12 +35,6 @@ export function renderTableHeader<TData>(
return headerGroups.map((headerGroup) =>
headerGroup.headers.map((header) => {
const { className, style } = getPinningStyles(header.column);
- const accessorKey: string = (
- header.column.columnDef as AccessorKeyColumnDefBase<TData>
- )?.accessorKey as string;
- const lookupKey: string = accessorKey ?? header.column.id;
- const headerHoverTitle: string | undefined =
- headerTooltip?.[lookupKey] || undefined;
return (
<TableHead
key={header.id}
@@ -51,19 +43,13 @@ export function renderTableHeader<TData>(
className,
)}
style={style}
- title={headerHoverTitle}
ref={(thead) => {
columnSizingHandler(thead, table, header.column);
}}
>
- {header.isPlaceholder ? null : (
- <div title={headerHoverTitle} className="contents">
- {flexRender(
- header.column.columnDef.header,
- header.getContext(),
- )}
- </div>
- )}
+ {header.isPlaceholder
+ ? null
+ : flexRender(header.column.columnDef.header, header.getContext())}
</TableHead>
);
}),
@@ -168,6 +154,8 @@ export const DataTableBody = <TData,>({
}
};
+ const hoverTemplate = table.getState().cellHoverTemplate || null;
+
return (
<TableBody onKeyDown={handleCellsKeyDown} ref={tableRef}>
{table.getRowModel().rows?.length ? (
@@ -180,15 +168,17 @@ export const DataTableBody = <TData,>({
rowViewerPanelOpen && viewedRowIdx === rowIndex;
// Compute hover title once per row using all visible cells
- const hoverTemplate = table.getState().cellHoverTemplate || null;
- const visibleCells = row.getVisibleCells?.() ?? [
- ...row.getLeftVisibleCells(),
- ...row.getCenterVisibleCells(),
- ...row.getRightVisibleCells(),
- ];
- const rowTitle = hoverTemplate
- ? applyHoverTemplate(hoverTemplate, visibleCells)
- : undefined;
+ let rowTitle: string | undefined;
+ if (hoverTemplate) {
+ const visibleCells = row.getVisibleCells?.() ?? [
+ ...row.getLeftVisibleCells(),
+ ...row.getCenterVisibleCells(),
+ ...row.getRightVisibleCells(),
+ ];
+ rowTitle = hoverTemplate
+ ? applyHoverTemplate(hoverTemplate, visibleCells)
+ : undefined;
+ }
return (
<TableRow
diff --git a/frontend/src/plugins/impl/DataTablePlugin.tsx b/frontend/src/plugins/impl/DataTablePlugin.tsx
index 99c0a5ac0d..dcf7d8bb92 100644
--- a/frontend/src/plugins/impl/DataTablePlugin.tsx
+++ b/frontend/src/plugins/impl/DataTablePlugin.tsx
@@ -348,7 +348,6 @@ export const DataTablePlugin = createPlugin<S>("marimo-table")
data={props.data.data}
value={props.value}
setValue={props.setValue}
- headerInfo={props.data.headerTooltip}
/>
</LazyDataTableComponent>
</TableProviders>
@@ -390,7 +389,6 @@ interface DataTableProps<T> extends Data<T>, DataTableFunctions {
enableFilters?: boolean;
cellStyles?: CellStyleState | null;
hoverTemplate?: string | null;
- headerInfo?: Record<string, string> | undefined;
toggleDisplayHeader?: () => void;
host: HTMLElement;
cellId?: CellId | null;
@@ -915,7 +913,6 @@ const DataTableComponent = ({
cellSelection={cellSelection}
cellStyling={cellStyles}
hoverTemplate={hoverTemplate}
- headerTooltip={headerTooltip}
downloadAs={showDownload ? downloadAs : undefined}
enableSearch={enableSearch}
searchQuery={searchQuery}