Skip to content

Commit c1d7377

Browse files
authored
make scrollTo{Column,Row} take precedence (bvaughn#1130)
* make scrollTo{Column,Row} take precedence * typo
1 parent dcef5bc commit c1d7377

File tree

2 files changed

+16
-31
lines changed

2 files changed

+16
-31
lines changed

docs/Grid.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ A windowed grid of elements. `Grid` only renders cells necessary to fill itself
3636
| scrollingResetTimeInterval | Number | | Wait this amount of time after the last scroll event before resetting Grid `pointer-events`; defaults to 150ms. |
3737
| scrollLeft | Number | | Horizontal offset |
3838
| scrollToAlignment | String | | Controls the alignment of scrolled-to-cells. The default ("_auto_") scrolls the least amount possible to ensure that the specified cell is fully visible. Use "_start_" to always align cells to the top/left of the `Grid` and "_end_" to align them bottom/right. Use "_center_" to align specified cell in the middle of container. |
39-
| scrollToColumn | Number | | Column index to ensure visible (by forcefully scrolling if necessary) |
40-
| scrollToRow | Number | | Row index to ensure visible (by forcefully scrolling if necessary) |
39+
| scrollToColumn | Number | | Column index to ensure visible (by forcefully scrolling if necessary). Takes precedence over `scrollLeft`. |
40+
| scrollToRow | Number | | Row index to ensure visible (by forcefully scrolling if necessary). Takes precedence over `scrollTop`. |
4141
| scrollTop | Number | | Vertical offset |
4242
| style | Object | | Optional custom inline style to attach to root `Grid` element. |
4343
| tabIndex | Number | | Optional override of tab index default; defaults to `0`. |

source/Grid/Grid.js

+14-29
Original file line numberDiff line numberDiff line change
@@ -814,37 +814,22 @@ class Grid extends React.PureComponent<Props, State> {
814814
) {
815815
newState.scrollLeft = 0;
816816
newState.scrollTop = 0;
817+
818+
// only use scroll{Left,Top} from props if scrollTo{Column,Row} isn't specified
819+
// scrollTo{Column,Row} should override scroll{Left,Top}
817820
} else if (
818-
nextProps.scrollLeft !== prevState.scrollLeft ||
819-
nextProps.scrollTop !== prevState.scrollTop
821+
(nextProps.scrollLeft !== prevState.scrollLeft &&
822+
nextProps.scrollToColumn < 0) ||
823+
(nextProps.scrollTop !== prevState.scrollTop && nextProps.scrollToRow < 0)
820824
) {
821-
// this handles the weird edge case where setting scrollToColumn in
822-
// multigrid was causing multiple getDerivedStateFromProps calls. Overriding
823-
// the state set in the first time.
824-
// We should warn since if scrollTo{column,row} and scroll{left,top} is specified,
825-
// scrollTo{column,row} should override.
826-
if (
827-
nextProps.scrollToColumn > 0 &&
828-
prevState.scrollLeft &&
829-
nextProps.scrollLeft === 0
830-
) {
831-
//NOOP
832-
} else if (
833-
nextProps.scrollToRow > 0 &&
834-
prevState.scrollTop &&
835-
nextProps.scrollTop === 0
836-
) {
837-
//NOOP
838-
} else {
839-
Object.assign(
840-
newState,
841-
Grid._getScrollToPositionStateUpdate({
842-
prevState,
843-
scrollLeft: nextProps.scrollLeft,
844-
scrollTop: nextProps.scrollTop,
845-
}),
846-
);
847-
}
825+
Object.assign(
826+
newState,
827+
Grid._getScrollToPositionStateUpdate({
828+
prevState,
829+
scrollLeft: nextProps.scrollLeft,
830+
scrollTop: nextProps.scrollTop,
831+
}),
832+
);
848833
}
849834

850835
let {instanceProps} = prevState;

0 commit comments

Comments
 (0)