use FixedSizeList ;
scroll horizontal ;
onScroll event not trigger;
Sorry, I don't have time to look at bugs that don't include repro code. Please provide a Code Sandbox or similar.
https://codesandbox.io/embed/thirsty-almeida-2bkoq
there is a demo .
you can scroll and see the console
Your demo shows a vertical list component. onScroll is only be called when you scroll in the primary direction (in this case, vertical). I can see where the docs might not be detailed enough in this regard.
@bvaughn In this case, how can I get the horizontal scroll event ?
i need this to sync this scroll with another div.
On the
const listContainerRef = useRef(null)
useLayoutEffect(() => {
if(listContainerRef) {
listContainerRef.current.addEventListener('scroll', function() {
//do something with scrollLeft
})
return () => listContainerRef.current.removeEventListener('scroll', function() {
//do soemthing with scrollLeft
})
}
}, [listContainerRef])
<List
itemData={{ ItemRenderer: children, stickyIndices }}
ref={listRef}
outerRef={listContainerRef}
>
But somehow adding an event listener to the container ref doesn't work in this case so I ended up with the following where I pass in a class name and adding event listener to the document instead.
const listScroll = (e) => {
if(e.target.className === 'headless-table-list') {
//do something with scrollLeft
}
}
useLayoutEffect(() => {
if(listContainerRef) {
document.addEventListener('scroll', listScroll, true);
return () => document.removeEventListener('scroll', listScroll)
}
}, [listContainerRef])
<List
itemData={{ ItemRenderer: children, stickyIndices }}
className="headless-table-list"
ref={listRef}
outerRef={listContainerRef}
>
Or we are supposed to use Grid instead of List but I am too far down the path with List.
Most helpful comment
@bvaughn In this case, how can I get the horizontal scroll event ?
i need this to sync this scroll with another div.