wellyshen / react-cool-virtual

😎 ♻️ A tiny React hook for rendering large datasets like a breeze.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

scrollToItem doesn't work as expected when using StickyHeaders

ROTGP opened this issue · comments

commented

Bug Report

Describe the Bug

scrollToItem doesn't work as expected when using StickyHeaders. When scrolling to an index, and align is 'start', it should be scrolled to the top, but still be visible underneath any 'stuck' headers. Currently, it's scrolled to the absolute top, and thus, is obscured by sticky heads.

How to Reproduce

Create a a demo with sticky headers and try to scrollToItem to an index which is not a sticky header.

@ROTGP Thank you, I will investigate it soon.

@ROTGP Hey mate, I think it's the expected behavior because it's how a sticky item works. If you want an item to be scrolled on the top without being covered by the sticky item, maybe you can try this:

// The scroll item will be under the sticky item
scrollToItem({ index: 10 - 1, align: "start" });
commented

I don't really agree with you. And your approach will not work when scrolling to variable-sized rows/headers, but thanks for your response.

@ROTGP The style of a sticky item is set at the application level. So you can manipulate it for your case. The userScroll can tell you the scrolling is by the user or the scrolling method and the callback of the scrollToItem can tell you when the is finishing.