Skip to content

Commit b6dbeb0

Browse files
committed
fix: add gap to itemSize
1 parent be2daeb commit b6dbeb0

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/VirtualList.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,22 @@ export const VirtualList = forwardRef(function <ITEM>(
130130
setListSize(list.current!.clientHeight)
131131
// get avg item size
132132
if (props.itemSize == null) {
133+
// get gap
134+
const listInnerEl = listInner.current as HTMLElement
135+
let gap = parseFloat(getComputedStyle(listInnerEl).rowGap)
136+
gap = isNaN(gap) ? 0 : gap
137+
//
133138
let count = 0
134139
let totalHeight = 0
135140
const persistentIndices = new Set(props.persistentIndices || [])
136141
let i = -1
137-
for (const el of listInner.current!.children) {
142+
for (const el of listInnerEl.children) {
138143
i++
139144
if (persistentIndices.has(visibleIndices[i])) {
140145
continue
141146
}
142147
const style = getComputedStyle(el)
143-
totalHeight += (el as HTMLElement).offsetHeight + parseFloat(style.marginTop) + parseFloat(style.marginBottom)
148+
totalHeight += (el as HTMLElement).offsetHeight + parseFloat(style.marginTop) + parseFloat(style.marginBottom) + gap
144149
count++
145150
}
146151
setItemSize(totalHeight / count)

0 commit comments

Comments
 (0)