bvaughn / react-window

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

Scrolls to top on rerender #632

Closed tommhuth closed 2 years ago

tommhuth commented 2 years ago

I'm using react-window with Mui's Autocomplete and it almost works, except for one thing: when a user makes a selection and the select list stays open (via the disableCloseOnSelect prop), react-window scrolls to the top of the list.

Is this expected behavior? How can I get my list to stay where it is even when parent rerenders?

tommhuth commented 2 years ago

For anyone finding this: the problem was my ListboxComponent component on the Mui Autocomplete not being referentially stable (inline arrow function). Moving the definition out of the render function solved the problem.

jakeledoux commented 2 years ago

Thank you for coming back and posting your solution! It helped me :)