cmdk icon indicating copy to clipboard operation
cmdk copied to clipboard

Items added asynchronously cause the active item to be reset

Open zgreen opened this issue 3 years ago • 2 comments

My use case is an infinitely scrolling list, that loads more items as the user scrolls or arrows down. Whenever the items in the list is changed, the active index appears to be reset to zero.

Here's a simple reproduction (it doesn't actually load more on scroll, it simply loads more on an interval). If you start using the down arrow to move down the list, you'll see your position gets lost as new items are concatenated onto the end of the list.

https://codesandbox.io/s/nifty-wood-4u4cnx?file=/src/App.tsx

This is less of an issue when scrolling with the mouse, because the pointer sets a new active item on whatever it hovers over. So the primary thing I'm hoping to solve is preserving the active item when using arrow keys.

Thanks very much for this library! If you need a PR, I may be able to contribute—I recognize this might be non-trivial.

zgreen avatar Mar 02 '23 23:03 zgreen

Facing similar issues when using virtualization. Because the elements are dynamically added, the focused element goes back to the start.

deshiknaves avatar Jan 23 '24 06:01 deshiknaves

I've also noticed that even hovering over an element with virtualization is very laggy, which can also affect the overall UX of using this component with virtualization.

stmchan93 avatar Jun 01 '24 22:06 stmchan93