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 scroll doesn't reset to top #115

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/FixedDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,18 @@ var FixedDataTable = React.createClass({

this._scrollHelper.setViewportHeight(bodyHeight);
Copy link
Contributor

Choose a reason for hiding this comment

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

After some investigation, it seems the real bug is this line. We update the viewport height after having calculated the rows. This makes our clamping operation invalid.

I think all we really need to do is check if scrollTop === scrollY.


// This calculation is synonymous to Element.scrollTop
var scrollTop = Math.abs(firstRowOffset - this._scrollHelper.getRowPosition(firstRowIndex));
// This case can happen when the user is completely scrolled down and resizes the viewport to be taller vertically.
// This is because we set the viewport height after having calculated the rows
if (scrollTop !== scrollY) {
scrollTop = maxScrollY;
scrollState = this._scrollHelper.scrollTo(scrollTop);
firstRowIndex = scrollState.index;
firstRowOffset = scrollState.offset;
scrollY = scrollState.position;
}

// The order of elements in this object metters and bringing bodyHeight,
// height or useGroupHeader to the top can break various features
var newState = {
Expand All @@ -1078,7 +1090,6 @@ var FixedDataTable = React.createClass({
scrollContentHeight,
scrollX,
scrollY,

// These properties may overwrite properties defined in
// columnInfo and props
bodyHeight,
Expand Down Expand Up @@ -1161,7 +1172,6 @@ var FixedDataTable = React.createClass({
}
},


_onHorizontalScroll(/*number*/ scrollPos) {
if (this.isMounted() && scrollPos !== this.state.scrollX) {
if (!this._isScrolling) {
Expand Down