glide-data-grid icon indicating copy to clipboard operation
glide-data-grid copied to clipboard

Auto-scroll to grid selection inconsistent

Open gkn opened this issue 3 years ago • 8 comments
trafficstars

Hi,

I am attempting to sync two grids so that their horizontal grid selection and scroll is in sync visually, using the "Controlled Selection" story as inspiration, i.e. utilizing useState<GridSelection>

This works pixel perfectly in version 5.1.0, but in 5.1.1. it will sometimes "miss" an occasional "scroll" when setting the selection, resulting in a "one col off" situation. This will typically adjust/fix itself when moving to an adjacent cell.

PS. There is also a console.log("Cancel") left by in data-editor.tsx at line 2845

gkn avatar Sep 27 '22 14:09 gkn

This bug seems to be present in 5.1.0 too I am afraid.

gkn avatar Sep 27 '22 14:09 gkn

Fixed the console log. Can you make a replay.io of the failure?

jassmith avatar Sep 27 '22 15:09 jassmith

I will try to duplicate the issue, hopefully within a few days. Unable to share client work...

gkn avatar Sep 27 '22 15:09 gkn

OK, I made a sample showing this issue.

It takes some fiddling; Something like: Select a cell in the top grid and use the right arrow key to move to the end, move keydown. Keep using the arrow left/right key to scroll right and left (keep keys down and make sure to scroll a "page" sideways. Keep doing that until you see the error, example screen shot below.

NOTE I also noticed that in the Glide data grid storybook stories, you will always see a complete rightmost cell when selecting to the right (same to the left). In this sample the rightmost cell will sometimes be clipped, and sometimes not (alternating actually) - i.e. the grid will not always scroll the cell into view. I suspect this is related to the original issue.

Please find a working sample here:

https://playcode.io/972515

Screen shot from sample:

image

gkn avatar Sep 28 '22 11:09 gkn

@jassmith Would you rather recommend utilizing initial scrollOffsetX, scrollOffsetY and scrollTo to sync scrolling on multiple grids? Can you advice how to capture scroll change events on a grid? P.S. Thanks for open sourcing this awesome grid :)

gkn avatar Sep 29 '22 11:09 gkn

I would not use the scrollOffsetX/Y unless you have very special needs. I am still trying to work out what is going wrong here.

jassmith avatar Sep 30 '22 01:09 jassmith

If I enable smoothScrollX={true} I can no longer reproduce the issue, can you confirm?

jassmith avatar Sep 30 '22 01:09 jassmith

Can confirm. That helped a lot! Thanks @jassmith

gkn avatar Sep 30 '22 05:09 gkn

smoothScrollY={true} also worked for me, I wanted to align the last row to the bottom of the grid. @jassmith would you say this is a reasonable workaround? From the docs, it says disabling smoonthScrollY can drastically improve visual performance when scrolling. I really can't tell if there's a performance difference when scrolling and smoothScrollY is enabled or disabled.

camposfyi avatar Feb 27 '23 21:02 camposfyi

After looking into this more. This is caused by accumulated offset errors. For now I do not intend to fix this as smooth scrolling is increasingly the dominant method of using the Grid and a lot of the performance impacts are entirely mitigated.

jassmith avatar Dec 18 '23 06:12 jassmith