bvaughn / react-window

React components for efficiently rendering large lists and tabular data
https://react-window.now.sh/
MIT License
15.82k stars 785 forks source link

scrollToItem only if the item is not visible? #710

Closed icd2k3 closed 1 month ago

icd2k3 commented 1 year ago

Is this possible? I only want to scroll to an item if it's outside of the viewable area.

timminata commented 1 year ago

Pretty sure this is already possible, I was playing with it today: You can use the "smart" option:

listRef.current?.scrollToItem(scrollToIndex, 'smart');

From the JSDocs:

- smart
 If the item is already visible, don't scroll at all.
 If it is less than one viewport away, scroll as little as possible so that it becomes visible.
 If it is more than one viewport away, scroll so that it is centered within the list.