fix: Propogation of Scroll Events when Scroll Position is at a Boundary#2166
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2166 +/- ##
==========================================
- Coverage 46.68% 46.66% -0.02%
==========================================
Files 691 692 +1
Lines 38588 38625 +37
Branches 9806 9814 +8
==========================================
+ Hits 18014 18025 +11
- Misses 20563 20589 +26
Partials 11 11
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
| event.stopPropagation(); | ||
| event.preventDefault(); | ||
| // Check if we're at the top or bottom of the grid | ||
| if (top >= 0 && topOffset !== 0) { |
There was a problem hiding this comment.
Scrolling seems to be broken in IrisGrid sample in styleguide. I think something isn't working as expected here. Also, a little confused how this is checking top or bottom? Is this a stale comment, or is there something missing in the code here?
There was a problem hiding this comment.
Taking a look rn
|
|
||
| // Check if at the top and attempting to scroll up | ||
| // Or at the bottom and attempting to scroll down | ||
| if ((top === 0 && deltaY < 0) || (top >= rowCount - 1 && deltaY > 0)) { |
There was a problem hiding this comment.
Something doesn't seem right here that you are introducing a return that wasn't there before.
There was a problem hiding this comment.
Well we return because we are no longer looking to scroll, and thus handle movement of the wheel, if we are attempting to scroll down if we are at the bottom, or scroll up if we are at the top.
But I am looking into to modify. the logic right now, since as per your observation, the IrisGrid is behaving quite differently then the Grid in terms of the scroll.
bmingles
left a comment
There was a problem hiding this comment.
IrisGrid example in styleguide is broken
|
Still working on implementing fix, the initial approach of returning early or having it stop propogation at the bottom using the |
|
Ready for re-review |
|
|
||
| // Check if at the top and attempting to scroll up | ||
| // Or at the bottom and attempting to scroll down | ||
| if ((top === 0 && deltaY < 0) || (top === lastTop && deltaY > 0)) { |
There was a problem hiding this comment.
This seems to work, but I'm not the most familiar with how Grid was implemented. Would probably be good to check with @mofojed to make sure there aren't any edge cases we are missing here.
There was a problem hiding this comment.
ah, I think this can break horizontal scrolling when at top / bottom boundary since it's hard to scroll horizontally exactly without at least some deltaY if you are scrolling via a trackpad
| // Or at the bottom and attempting to scroll down | ||
| // Or at the left and attempting to scroll left | ||
| // Or at the right and attempting to scroll right | ||
| if ( |
There was a problem hiding this comment.
I think you need something that only returns if neither vertical or horizontal movement will result from the delta.
e.g. I haven't tested but something like:
const willScrollX = (deltaX < 0 && left > 0) || (deltaX > 0 && left < lastLeft)
const willScrollY = (deltaY < 0 && top > 0) || (deltaY > 0 && top < lastTop)
if (!willScrollX && !willScrollY) {
return
}There was a problem hiding this comment.
It is behaving the same as my commit, but makes more sense semantically, pushed change.
bmingles
left a comment
There was a problem hiding this comment.
Looks good to me. I tested scenarios where there were page level horizontal + vertical scrollbars. Grid maintains control while you can still control, and then passes control to page at boundaries. Also verified it no longer stutters.
| metrics.rowHeight | ||
| ); | ||
|
|
||
| // Check if we're at the edge of the grid and attempting to scroll |
There was a problem hiding this comment.
@mofojed this works for me with all cases I tested. I'm not very familiar with how lastTop and lastLeft are actually implemented or if there are nuances here we are missing. Any concerns on your part?
There was a problem hiding this comment.
There is one nuance that's missing. To give a little bit of context:
- The way we handle scrolling is by keeping track of the cell index that is in the top left, and then keeping track of the pixel offset within that cell. We do that so we can support very large grids and grids with variable width/height cells (since the width of a column may change after we've fetched data for it, we resize to match the data).
left/topare the index of the cell in the top leftleftOffset/topOffsetis the pixel offset within that cell that's in the top left- Current scroll position is the position of the top/left cell + the offset
Here we're just checking left, but you're not checking leftOffset or topOffset. You should check if (left > 0 || leftOffset > 0) && deltaX < 0 to check if you can scroll left (same with the top).
Actually just to be safe - I'd just track the initial values for all those variables left, top, leftOffset, and topOffset, and then just at the end of this method before this.setViewState check if they haven't changed, and if they haven't, don't bother setting them or eating the event. That seems like the safest.
There was a problem hiding this comment.
@mofojed I thought I saw some scenarios where scrolling really fast could result in no changes to those values for a particular pass and allowing the event to propagate when the user is actually still scrolling. Possible I wasn't incorporating all 4 checks, but just calling out as something we'll want to test.
There was a problem hiding this comment.
I think @mofojed suggestion here was to remove this section and just have the check at the end that you added below. I'll let him confirm, but I tested again using only the code at the end, and that seems to work as expected. I don't think we need this code at the beginning anymore.
There was a problem hiding this comment.
Ahh I might have misinterpreted, I thought just to be safe meant that the check at the bottom would be a failsafe, not the only check. Will test by removing initial code and repush accordingly.
| metrics.rowHeight | ||
| ); | ||
|
|
||
| // Check if we're at the edge of the grid and attempting to scroll |
There was a problem hiding this comment.
There is one nuance that's missing. To give a little bit of context:
- The way we handle scrolling is by keeping track of the cell index that is in the top left, and then keeping track of the pixel offset within that cell. We do that so we can support very large grids and grids with variable width/height cells (since the width of a column may change after we've fetched data for it, we resize to match the data).
left/topare the index of the cell in the top leftleftOffset/topOffsetis the pixel offset within that cell that's in the top left- Current scroll position is the position of the top/left cell + the offset
Here we're just checking left, but you're not checking leftOffset or topOffset. You should check if (left > 0 || leftOffset > 0) && deltaX < 0 to check if you can scroll left (same with the top).
Actually just to be safe - I'd just track the initial values for all those variables left, top, leftOffset, and topOffset, and then just at the end of this method before this.setViewState check if they haven't changed, and if they haven't, don't bother setting them or eating the event. That seems like the safest.
bmingles
left a comment
There was a problem hiding this comment.
Changed look good. Tested in styleguide. Things seem to work as expected.
mofojed
left a comment
There was a problem hiding this comment.
Just some cleanup but looks good
Closes #2101