Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-window-infinite-loader material-ui autocomplete

I am trying to show an infinite scrolled list inside a material-ui Autocomplete dropdown list, using react-window-infinite-loader. When I scroll to the bottom of the list, I want to fetch the next page of items from the server. I created a codesandbox example which combines the material-ui Autocomplete example for a virtualized list with the react-window-infinite-loader example. When I scroll to the bottom of the list, the next page of data is loaded, however something is causing the list to scroll back to the top. How can I keep the scroll position after new data is loaded?

Thanks!

like image 898
Bernard Wolff Avatar asked Nov 23 '19 23:11

Bernard Wolff


1 Answers

I got this to work by using the useAutocomplete hook. I created a sandbox which shows the working code: https://codesandbox.io/s/material-demo-0fbyb

There is only one problem, that I still cannot figure out. When pressing the down arrow key on the keyboard to select items in the list, you can select items beyond the visible "window" of items. There must be a way to get the list to scroll to the selected item. I am guessing this is because the autocomplete ref needs to be set on the FixedSizeList component, but how can I do this when the InfiniteLoader also needs to pass a ref to the FixedSizeList component?

like image 109
Bernard Wolff Avatar answered Oct 21 '22 00:10

Bernard Wolff