Skip to content

Commit 3403db4

Browse files
committed
fix prevHeight
1 parent 31bbfe9 commit 3403db4

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,11 @@ const AnalyticalTable = forwardRef<AnalyticalTableDomRef, AnalyticalTablePropTyp
392392
tableInstance(tableInstanceRef.current);
393393
}
394394

395-
const titleBarRef = useRef(null);
396-
const extensionRef = useRef(null);
397-
const headerRef = useRef(null);
398-
399-
const extensionsHeight = getCombinedElementsHeight(0, titleBarRef, extensionRef, headerRef);
395+
const prevExtensionsHeight = useRef<number>(0);
396+
const titleBarRef = useRef<HTMLElement>(null);
397+
const extensionRef = useRef<HTMLElement>(null);
398+
const headerRef = useRef<HTMLElement>(null);
399+
const extensionsHeight = getCombinedElementsHeight(prevExtensionsHeight, titleBarRef, extensionRef, headerRef);
400400

401401
const internalRowHeight = getRowHeight(rowHeight, tableRef);
402402
const internalHeaderRowHeight = headerRowHeight ?? internalRowHeight;

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,18 +177,23 @@ export function getLeafHeaders(header) {
177177
return leafHeaders;
178178
}
179179

180-
export const getCombinedElementsHeight = (prevHeight: number, ...refs: RefObject<HTMLElement>[]): number => {
180+
export const getCombinedElementsHeight = (
181+
prevHeightRef: RefObject<number>,
182+
...refs: RefObject<HTMLElement>[]
183+
): number => {
184+
const prevHeight = prevHeightRef.current;
181185
let height = 0;
182186

183187
for (const ref of refs) {
184188
const el = ref.current;
185189
if (!el) {
186190
continue;
187191
}
188-
const elementHeight = el.offsetHeight;
189-
height += elementHeight;
192+
height += el.offsetHeight;
190193
}
191-
192194
// Math.abs is required, because of layout thrashing (rounding errors)
193-
return Math.abs(prevHeight - height) > 1 ? height : prevHeight;
195+
const updatedHeight = Math.abs(prevHeight - height) > 1 ? height : prevHeight;
196+
prevHeightRef.current = updatedHeight;
197+
198+
return updatedHeight;
194199
};

0 commit comments

Comments
 (0)