From dcf44bce2e273c6de473d5779567732c5a2841be Mon Sep 17 00:00:00 2001 From: phphe Date: Thu, 7 Mar 2024 22:11:05 +0800 Subject: [PATCH] fix: ignore display none or position absolute fixed when compute avg item size --- lib/VirtualList.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/VirtualList.tsx b/lib/VirtualList.tsx index 5eed19b..71f6b26 100644 --- a/lib/VirtualList.tsx +++ b/lib/VirtualList.tsx @@ -149,6 +149,12 @@ export const VirtualList = forwardRef(function ( continue } const style = getComputedStyle(el) + if (style.display === 'none') { + continue + } + if (style.position !== 'static' && style.position !== 'relative') { + continue + } totalHeight += (el as HTMLElement).offsetHeight + parseFloat(style.marginTop) + parseFloat(style.marginBottom) + gap count++ }