Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with empty space in table if row heights change (#510) #511

Merged
merged 2 commits into from
Mar 5, 2020

Conversation

wcjordan
Copy link
Member

@wcjordan wcjordan commented Feb 11, 2020

Description

Fix issue with empty space in table if row heights change

This can happen if you scroll to the last row of the Expanded rows
example. Then expand and collapse the last row.

Primary: @pradeepnschrodinger

Motivation and Context

Fixes issue #510

How Has This Been Tested?

Tested on the Expanded Rows example, both w/ 2000 rows and w/ 3 rows

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.

This can happen if you scroll to the last row of the Expanded rows
example.  Then expand and collapse the last row.
while (rowIdx >= 0 && totalHeight < maxAvailableHeight) {
totalHeight += updateRowHeight(state, rowIdx);
startIdx = rowIdx;
rowIdx += reverseStep;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless there's intention to take bigger steps in the future, can we remove reverseStep, and then --rowIdx; here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's fine. Will do

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -145,6 +145,23 @@ function calculateRenderedRowRange(state, scrollAnchor) {
rowIdx += step;
}

/* Handle the case where we rows have shrunk and we don't have enough content
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: omit first "we"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can do

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// Calculate offset needed to position last row at bottom of viewport
// This should be negative and represent how far the first row needs to be offscreen
firstOffset = Math.min(availableHeight - totalHeight, 0);
firstOffset = firstOffset + Math.min(availableHeight - totalHeight, 0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me that this change won't affect current behavior when lastIndex !== undefined. Can we guarantee that firstOffset === 0 in that case? Otherwise the offset will be different here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ya, that's a bit confusing.

The offset is going to always be 0 when the lastIndex is set. That's because the last index is used to say, "scroll this row into view as the last row of the table." Whenever we do that we're putting that row flush so it's fully in view and not offset. You can verify this by looking at all the cases in scrollAnchor.js.

I'll add a comment here which captures something like this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment added:

// NOTE (jordan): The first offset should always be 0 when lastIndex is defined
// since we don't currently support scrolling the last row into view with an offset.

@wcjordan
Copy link
Member Author

@pradeepnschrodinger when you get a chance, could you give this a review? Thanks

In this case process earlier rows as needed and act as if we've scrolled to the last row.
*/
let forceScrollToLastRow = false;
if (totalHeight < maxAvailableHeight && rowIdx === rowsCount && lastIndex === undefined) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the lastIndex undefined check required?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we're anchoring to the lastIndex then we've already been stepping from the last index row upwards towards the top of the viewport. If we didn't find enough row content, then stepping upwards more won't help.

A follow up question would be whether we need to step down to rows below the last index in that case. I don't think so, but if you can come up with a case to try, I'm happy to test it out.

@wcjordan wcjordan added this to the v1.1 milestone Mar 3, 2020
@wcjordan wcjordan merged commit 2028ecb into master Mar 5, 2020
@wcjordan wcjordan deleted the Issue-510-ExpandedRowsScroll branch March 5, 2020 19:44
@wcjordan
Copy link
Member Author

wcjordan commented Apr 9, 2020

We're working to fix some issues introduced when moving to React's new lifecycle methods. Once those are resolved, we'll release v1.1.

@wcjordan
Copy link
Member Author

This is now released w/ v1.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants