From d4473c0e97bbe1cec7c8c067c5b95e48d655fb83 Mon Sep 17 00:00:00 2001 From: saket3395 Date: Fri, 31 Jul 2026 12:07:28 +0530 Subject: [PATCH] fix: correct DataTable tooltip position on paginated pages Fixes #1848. Tooltip row index was resolved against the virtualized (page-local) row twice: once when handling the mouse event, and again when matching the tooltip condition/data lookup. On page 1 these two resolutions coincide, masking the bug; on later pages they diverge, so tooltips render using the wrong row's position/data. Ports the fix from plotly/dash-table#906 (pre-merge into this repo): - cellEvents.ts: store the raw virtualized idx in currentTooltip.row instead of pre-resolving it, matching how handleMoveHeader already behaves for header tooltips. - tooltip.ts: resolve virtualized.indices[row - offset.rows] once, at lookup time in getSelectedTooltip, instead of relying on a pre-resolved value. Manually verified the diff is a faithful port of #906 and consistent with the surrounding code (handleMoveHeader already stores the raw idx). Not yet run through the JS build/test suite locally. --- .../src/dash-table/derived/table/tooltip.ts | 2 +- .../dash-table/src/dash-table/handlers/cellEvents.ts | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/components/dash-table/src/dash-table/derived/table/tooltip.ts b/components/dash-table/src/dash-table/derived/table/tooltip.ts index 54620dea99..f2651df322 100644 --- a/components/dash-table/src/dash-table/derived/table/tooltip.ts +++ b/components/dash-table/src/dash-table/derived/table/tooltip.ts @@ -42,7 +42,7 @@ function getSelectedTooltip( return ( !tt.if || (ifColumnId(tt.if, id) && - ifRowIndex(tt.if, row) && + ifRowIndex(tt.if, virtualized.indices[row - virtualized.offset.rows]) && ifFilter( tt.if, virtualized.data[row - virtualized.offset.rows] diff --git a/components/dash-table/src/dash-table/handlers/cellEvents.ts b/components/dash-table/src/dash-table/handlers/cellEvents.ts index 8ece59511e..6fc6d02dfa 100644 --- a/components/dash-table/src/dash-table/handlers/cellEvents.ts +++ b/components/dash-table/src/dash-table/handlers/cellEvents.ts @@ -160,13 +160,13 @@ export const handleEnter = ( idx: number, i: number ) => { - const {setState, virtualized, visibleColumns} = propsFn(); + const {setState, visibleColumns} = propsFn(); setState({ currentTooltip: { header: false, id: visibleColumns[i].id, - row: virtualized.indices[idx - virtualized.offset.rows] + row: idx } }); }; @@ -202,15 +202,14 @@ export const handleMove = ( idx: number, i: number ) => { - const {currentTooltip, setState, virtualized, visibleColumns} = propsFn(); + const {currentTooltip, setState, visibleColumns} = propsFn(); const c = visibleColumns[i]; - const realIdx = virtualized.indices[idx - virtualized.offset.rows]; if ( currentTooltip && currentTooltip.id === c.id && - currentTooltip.row === realIdx && + currentTooltip.row === idx && !currentTooltip.header ) { return; @@ -220,7 +219,7 @@ export const handleMove = ( currentTooltip: { header: false, id: c.id, - row: realIdx + row: idx } }); };