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
8 changes: 5 additions & 3 deletions src/hooks/useHeights.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import findDOMNode from 'rc-util/lib/Dom/findDOMNode';
import raf from 'rc-util/lib/raf';
import type { GetKey } from '../interface';
import CacheMap from '../utils/CacheMap';
import { getOuterHeight } from '../utils/outerHeight';

export default function useHeights<T>(
getKey: GetKey<T>,
Expand All @@ -26,9 +27,10 @@ export default function useHeights<T>(
instanceRef.current.forEach((element, key) => {
if (element && element.offsetParent) {
const htmlElement = findDOMNode<HTMLElement>(element);
const { offsetHeight } = htmlElement;
if (heightsRef.current.get(key) !== offsetHeight) {
heightsRef.current.set(key, htmlElement.offsetHeight);
const outerHeight = getOuterHeight(htmlElement)

if (heightsRef.current.get(key) !== outerHeight) {
heightsRef.current.set(key, outerHeight);
}
}
});
Expand Down
10 changes: 10 additions & 0 deletions src/utils/outerHeight.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* To get exact height to avoid scrolling deviation
*/
export const getOuterHeight = (el: HTMLElement) => {
let height = el.offsetHeight;
const computedStyle = window.getComputedStyle(el);
height += parseInt(computedStyle.marginTop, 10);
height += parseInt(computedStyle.marginBottom, 10);
return height;
}