Open BeSpunky opened 1 year ago
@BeSpunky I can do a "scrollToItem" based on these 'start', 'center', 'end', 'smart' options: https://react-window.vercel.app/#/examples/list/scroll-to-item
Considering the fact that most lists will shrink/change/etc based on user input/filtering, remembering the scroll position when re-rendering the complete list doesn't make logical sense to me. I would have to check too many variables: prompt size, list length, if choices match exactly, user input, etc.
I think 'center' makes the most sense based on my brief explorations/implementation.
I'll add it to my backlog to send the current scroll position in an onScroll handler, then allow the user to set a starting scrollPosition. That way if the script author knows the choices/etc will remain the same, the can manually control the scroll as well
It would be nice to have the flexibility of both. You either set a prop with center | start | end
and get out of the box scrolling, or use a custom function.
Makes sense? 🤔
Otherwise, I already see myself writing and reusing a util restoreScrollPosition
funcion...
Specifiying a
defaultValue
forarg
doesn't scroll the list to reveal the corresponding item.Current behavior The item indicated by
defaultValue
is selected ('15'
in this example), but not scrolled into view. Notice that when I press ⬆️ I do get to the adjacent item ('14'
), but the list started at the top.https://user-images.githubusercontent.com/47897671/236698045-fd7a4152-de83-41d3-9ca0-0a1ac5f71be4.mp4
Expected behavior The item is selected and scrolled into view.
Sidenote: scrolling into view should be deterministic and position the item at an expected position on the screen. Consider the following example where the kit doesn't disappear from the screen... Each call to
arg
should keep the list at its previous scroll position.