Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,21 @@ export default class ControlledTable extends PureComponent<ControlledTableProps>
document.removeEventListener('copy', this.handleCopy);
}

componentDidUpdate() {
componentDidUpdate(prevProps: ControlledTableProps) {
const {currentTooltip, data, setState, tooltip_data} = this.props;

// Row indices captured in currentTooltip (set on hover/move) are only
// valid for the data snapshot they were captured against. If rows are
// added/removed/reordered, those indices point at different rows now,
// so the tooltip would show stale position/content for a row that may
// no longer even be the one the user is hovering (dash#1848).
if (
currentTooltip &&
(data !== prevProps.data || tooltip_data !== prevProps.tooltip_data)
) {
setState({currentTooltip: undefined});
}

this.updateStylesheet();
this.updateUiViewport();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -62,7 +62,10 @@ function getSelectedTooltip(
? headerTooltip?.[row]
: headerTooltip;
} else {
tooltip = tooltip_data?.[row]?.[id];
tooltip =
tooltip_data?.[virtualized.indices[row - virtualized.offset.rows]]?.[
id
];
}

if (tooltip) {
Expand Down
11 changes: 5 additions & 6 deletions components/dash-table/src/dash-table/handlers/cellEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
});
};
Expand Down Expand Up @@ -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;
Expand All @@ -220,7 +219,7 @@ export const handleMove = (
currentTooltip: {
header: false,
id: c.id,
row: realIdx
row: idx
}
});
};
Expand Down
Loading