Skip to content

Commit e6869b4

Browse files
committed
feat: add prop triggerDistance
1 parent de348a5 commit e6869b4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/VirtualList.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ export type VirtualListProps<ITEM> = {
3333
* These items won't be removed when scroll. You can use css 'position:sticky' make them sticky.
3434
*/
3535
persistentIndices?: number[], // index[]
36+
/**
37+
* Minimum distance for triggering a calculation when scrolling.
38+
*/
39+
triggerDistance?: number,
3640
className?: string,
3741
style?: React.CSSProperties,
3842
} & OptionalKeys<typeof defaultProps>
@@ -127,7 +131,9 @@ export const VirtualList = forwardRef(function <ITEM>(
127131
}
128132
setlistSize(list.current!.clientHeight)
129133
const scrollTop2 = list.current!.scrollTop
130-
if (Math.abs(prevScrollTop.current - scrollTop2) > itemSize) {
134+
if (Math.abs(prevScrollTop.current - scrollTop2) > (props.triggerDistance ?? itemSize)) {
135+
console.log('triggerd');
136+
131137
setscrollTop(scrollTop2)
132138
prevScrollTop.current = scrollTop2
133139
} else if (scrollToIndexRef.current) {

0 commit comments

Comments
 (0)