Skip to content

Commit

Permalink
fix for [998](bvaughn#998) with test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
mengdage committed Jun 25, 2018
1 parent 886862d commit 15eac37
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default class DynamicHeightGrid extends React.PureComponent {
cellRenderer={this._cellRenderer}
rowCount={1000}
rowHeight={this._cache.rowHeight}
scrollToRow={100}
width={width}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default class DynamicWidthGrid extends React.PureComponent {
cellRenderer={this._cellRenderer}
rowCount={50}
rowHeight={35}
scrollToColumn={100}
width={width}
/>
);
Expand Down
50 changes: 50 additions & 0 deletions source/Grid/Grid.jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,56 @@ describe('Grid', () => {
expect(node.scrollTop).toBe(1920);
});

it('should not restore scrollLeft when scrolling left and recomputeGridSize with columnIndex smaller than scrollToColumn', () => {
const props = {
columnWidth: 50,
columnCount: 100,
height: 100,
rowCount: 100,
rowHeight: 20,
scrollToColumn: 50,
scrollToRow: 50,
width: 100,
};
const grid = render(getMarkup(props));

expect(grid.state.scrollLeft).toEqual(2450);

simulateScroll({grid, scrollLeft: 2250});
expect(grid.state.scrollLeft).toEqual(2250);
expect(grid.state.scrollDirectionHorizontal).toEqual(
SCROLL_DIRECTION_BACKWARD,
);

grid.recomputeGridSize({columnIndex: 30});
expect(grid.state.scrollLeft).toEqual(2250);
});

it('should not restore scrollTop when scrolling up and recomputeGridSize with rowIndex smaller than scrollToRow', () => {
const props = {
columnWidth: 50,
columnCount: 100,
height: 100,
rowCount: 100,
rowHeight: 20,
scrollToColumn: 50,
scrollToRow: 50,
width: 100,
};
const grid = render(getMarkup(props));

expect(grid.state.scrollTop).toEqual(920);

simulateScroll({grid, scrollTop: 720});
expect(grid.state.scrollTop).toEqual(720);
expect(grid.state.scrollDirectionVertical).toEqual(
SCROLL_DIRECTION_BACKWARD,
);

grid.recomputeGridSize({rowIndex: 20});
expect(grid.state.scrollTop).toEqual(720);
});

it('should restore scroll offset for column when row count increases from 0 (and vice versa)', () => {
const props = {
columnWidth: 50,
Expand Down
11 changes: 9 additions & 2 deletions source/Grid/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,15 @@ class Grid extends React.PureComponent<Props, State> {
// In this case the cDU handler can't know if they changed.
// Store this flag to let the next cDU pass know it needs to recompute the scroll offset.
this._recomputeScrollLeftFlag =
scrollToColumn >= 0 && columnIndex <= scrollToColumn;
this._recomputeScrollTopFlag = scrollToRow >= 0 && rowIndex <= scrollToRow;
scrollToColumn >= 0 &&
(this.state.scrollDirectionHorizontal === SCROLL_DIRECTION_FORWARD
? columnIndex <= scrollToColumn
: columnIndex >= scrollToColumn);
this._recomputeScrollTopFlag =
scrollToRow >= 0 &&
(this.state.scrollDirectionVertical === SCROLL_DIRECTION_FORWARD
? rowIndex <= scrollToRow
: rowIndex >= scrollToRow);

// Clear cell cache in case we are scrolling;
// Invalid row heights likely mean invalid cached content as well.
Expand Down

0 comments on commit 15eac37

Please sign in to comment.