Skip to content

Commit 8717614

Browse files
committed
fix(AnalyticalTable): safeguard extension, header, title height calc
1 parent 4d332d3 commit 8717614

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

packages/main/src/components/AnalyticalTable/index.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,12 @@ import type {
9090
DivWithCustomScrollProp,
9191
TableInstance,
9292
} from './types/index.js';
93-
import { getRowHeight, getSubRowsByString, tagNamesWhichShouldNotSelectARow } from './util/index.js';
93+
import {
94+
getObservedCombinedHeight,
95+
getRowHeight,
96+
getSubRowsByString,
97+
tagNamesWhichShouldNotSelectARow,
98+
} from './util/index.js';
9499
import { VerticalResizer } from './VerticalResizer.js';
95100

96101
// When a sorted column is removed from the visible columns array (e.g. when "popped-in"), it doesn't clean up the sorted columns leading to an undefined `sortType`.
@@ -391,10 +396,7 @@ const AnalyticalTable = forwardRef<AnalyticalTableDomRef, AnalyticalTablePropTyp
391396
const extensionRef = useRef(null);
392397
const headerRef = useRef(null);
393398

394-
const extensionsHeight =
395-
(titleBarRef.current?.offsetHeight ?? 0) +
396-
(extensionRef.current?.offsetHeight ?? 0) +
397-
(headerRef.current?.offsetHeight ?? 0);
399+
const extensionsHeight = getObservedCombinedHeight(0, titleBarRef, extensionRef, headerRef);
398400

399401
const internalRowHeight = getRowHeight(rowHeight, tableRef);
400402
const internalHeaderRowHeight = headerRowHeight ?? internalRowHeight;

packages/main/src/components/AnalyticalTable/util/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,19 @@ export function getLeafHeaders(header) {
176176
recurseHeader(header);
177177
return leafHeaders;
178178
}
179+
180+
export const getObservedCombinedHeight = (prevHeight: number, ...refs: RefObject<HTMLElement>[]): number => {
181+
let height = 0;
182+
183+
for (const ref of refs) {
184+
const el = ref.current;
185+
if (!el) {
186+
continue;
187+
}
188+
const elementHeight = el.offsetHeight;
189+
height += elementHeight;
190+
}
191+
192+
// Math.abs is required, because of layout thrashing (rounding errors)
193+
return Math.abs(prevHeight - height) > 1 ? height : prevHeight;
194+
};

0 commit comments

Comments
 (0)