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

Make rowIndex and columnIndex optional #174

Merged
merged 2 commits into from
Mar 16, 2019
Merged
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions src/__tests__/FixedSizeGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,10 @@ describe('FixedSizeGrid', () => {
rendered
.getInstance()
.scrollToItem({ columnIndex: 2, rowIndex: 2, align: 'auto' });
// Scroll down to row 10, without changing scrollLeft
rendered.getInstance().scrollToItem({ rowIndex: 10, align: 'auto' });
// Scroll left to column 0, without changing scrollTop
rendered.getInstance().scrollToItem({ columnIndex: 0, align: 'auto' });
Copy link
Owner

Choose a reason for hiding this comment

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

You aren't testing anything between these scrollToItem calls. That seems not great.

Copy link
Owner

Choose a reason for hiding this comment

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

Whoops. I misremembered how my own tests were written 😆 you're expecting on the mock calls below. 👍

expect(onItemsRendered.mock.calls).toMatchSnapshot();
});

Expand All @@ -497,6 +501,10 @@ describe('FixedSizeGrid', () => {
rendered
.getInstance()
.scrollToItem({ columnIndex: 99, rowIndex: 99, align: 'start' });
// Scroll up to row 10, without changing scrollLeft
rendered.getInstance().scrollToItem({ rowIndex: 10, align: 'start' });
// Scroll left to column 0, without changing scrollTop
rendered.getInstance().scrollToItem({ columnIndex: 0, align: 'start' });
expect(onItemsRendered.mock.calls).toMatchSnapshot();
});

Expand All @@ -519,6 +527,10 @@ describe('FixedSizeGrid', () => {
rendered
.getInstance()
.scrollToItem({ columnIndex: 1, rowIndex: 1, align: 'end' });
// Scroll down to row 10, without changing scrollLeft
rendered.getInstance().scrollToItem({ rowIndex: 10, align: 'end' });
// Scroll right to column 9, without changing scrollTop
rendered.getInstance().scrollToItem({ columnIndex: 9, align: 'end' });
expect(onItemsRendered.mock.calls).toMatchSnapshot();
});

Expand Down Expand Up @@ -547,6 +559,10 @@ describe('FixedSizeGrid', () => {
rendered
.getInstance()
.scrollToItem({ columnIndex: 99, rowIndex: 99, align: 'center' });
// Scroll up to row 10, without changing scrollLeft
rendered.getInstance().scrollToItem({ rowIndex: 10, align: 'center' });
// Scroll left to column 3, without changing scrollTop
rendered.getInstance().scrollToItem({ columnIndex: 3, align: 'center' });
expect(onItemsRendered.mock.calls).toMatchSnapshot();
});

Expand Down
16 changes: 16 additions & 0 deletions src/__tests__/VariableSizeGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ describe('VariableSizeGrid', () => {
rendered
.getInstance()
.scrollToItem({ columnIndex: 2, rowIndex: 2, align: 'auto' });
// Scroll down to row 10, without changing scrollLeft
rendered.getInstance().scrollToItem({ rowIndex: 10, align: 'auto' });
// Scroll left to column 0, without changing scrollTop
rendered.getInstance().scrollToItem({ columnIndex: 0, align: 'auto' });
expect(onItemsRendered.mock.calls).toMatchSnapshot();
});

Expand All @@ -212,6 +216,10 @@ describe('VariableSizeGrid', () => {
rendered
.getInstance()
.scrollToItem({ columnIndex: 9, rowIndex: 19, align: 'start' });
// Scroll up to row 10, without changing scrollLeft
rendered.getInstance().scrollToItem({ rowIndex: 10, align: 'start' });
// Scroll left to column 0, without changing scrollTop
rendered.getInstance().scrollToItem({ columnIndex: 0, align: 'start' });
expect(onItemsRendered.mock.calls).toMatchSnapshot();
});

Expand All @@ -234,6 +242,10 @@ describe('VariableSizeGrid', () => {
rendered
.getInstance()
.scrollToItem({ columnIndex: 1, rowIndex: 1, align: 'end' });
// Scroll down to row 10, without changing scrollLeft
rendered.getInstance().scrollToItem({ rowIndex: 10, align: 'end' });
// Scroll right to column 9, without changing scrollTop
rendered.getInstance().scrollToItem({ columnIndex: 9, align: 'end' });
expect(onItemsRendered.mock.calls).toMatchSnapshot();
});

Expand Down Expand Up @@ -262,6 +274,10 @@ describe('VariableSizeGrid', () => {
rendered
.getInstance()
.scrollToItem({ columnIndex: 9, rowIndex: 19, align: 'center' });
// Scroll up to row 10, without changing scrollLeft
rendered.getInstance().scrollToItem({ rowIndex: 10, align: 'center' });
// Scroll left to column 3, without changing scrollTop
rendered.getInstance().scrollToItem({ columnIndex: 3, align: 'center' });
expect(onItemsRendered.mock.calls).toMatchSnapshot();
});

Expand Down
96 changes: 96 additions & 0 deletions src/__tests__/__snapshots__/FixedSizeGrid.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,30 @@ Array [
"visibleRowStopIndex": 6,
},
],
Array [
Object {
"overscanColumnStartIndex": 1,
"overscanColumnStopIndex": 5,
"overscanRowStartIndex": 6,
"overscanRowStopIndex": 12,
"visibleColumnStartIndex": 2,
"visibleColumnStopIndex": 4,
"visibleRowStartIndex": 7,
"visibleRowStopIndex": 11,
},
],
Array [
Object {
"overscanColumnStartIndex": 0,
"overscanColumnStopIndex": 3,
"overscanRowStartIndex": 6,
"overscanRowStopIndex": 12,
"visibleColumnStartIndex": 0,
"visibleColumnStopIndex": 2,
"visibleRowStartIndex": 7,
"visibleRowStopIndex": 11,
},
],
]
`;

Expand Down Expand Up @@ -376,6 +400,30 @@ Array [
"visibleRowStopIndex": 99,
},
],
Array [
Object {
"overscanColumnStartIndex": 97,
"overscanColumnStopIndex": 99,
"overscanRowStartIndex": 7,
"overscanRowStopIndex": 13,
"visibleColumnStartIndex": 98,
"visibleColumnStopIndex": 99,
"visibleRowStartIndex": 8,
"visibleRowStopIndex": 12,
},
],
Array [
Object {
"overscanColumnStartIndex": 1,
"overscanColumnStopIndex": 5,
"overscanRowStartIndex": 7,
"overscanRowStopIndex": 13,
"visibleColumnStartIndex": 2,
"visibleColumnStopIndex": 4,
"visibleRowStartIndex": 8,
"visibleRowStopIndex": 12,
},
],
]
`;

Expand Down Expand Up @@ -429,6 +477,30 @@ Array [
"visibleRowStopIndex": 4,
},
],
Array [
Object {
"overscanColumnStartIndex": 0,
"overscanColumnStopIndex": 3,
"overscanRowStartIndex": 6,
"overscanRowStopIndex": 12,
"visibleColumnStartIndex": 0,
"visibleColumnStopIndex": 2,
"visibleRowStartIndex": 7,
"visibleRowStopIndex": 11,
},
],
Array [
Object {
"overscanColumnStartIndex": 7,
"overscanColumnStopIndex": 11,
"overscanRowStartIndex": 6,
"overscanRowStopIndex": 12,
"visibleColumnStartIndex": 8,
"visibleColumnStopIndex": 10,
"visibleRowStartIndex": 7,
"visibleRowStopIndex": 11,
},
],
]
`;

Expand Down Expand Up @@ -482,6 +554,30 @@ Array [
"visibleRowStopIndex": 99,
},
],
Array [
Object {
"overscanColumnStartIndex": 97,
"overscanColumnStopIndex": 99,
"overscanRowStartIndex": 9,
"overscanRowStopIndex": 15,
"visibleColumnStartIndex": 98,
"visibleColumnStopIndex": 99,
"visibleRowStartIndex": 10,
"visibleRowStopIndex": 14,
},
],
Array [
Object {
"overscanColumnStartIndex": 0,
"overscanColumnStopIndex": 3,
"overscanRowStartIndex": 9,
"overscanRowStopIndex": 15,
"visibleColumnStartIndex": 0,
"visibleColumnStopIndex": 2,
"visibleRowStartIndex": 10,
"visibleRowStopIndex": 14,
},
],
]
`;

Expand Down
96 changes: 96 additions & 0 deletions src/__tests__/__snapshots__/VariableSizeGrid.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,30 @@ Array [
"visibleRowStopIndex": 5,
},
],
Array [
Object {
"overscanColumnStartIndex": 1,
"overscanColumnStopIndex": 6,
"overscanRowStartIndex": 7,
"overscanRowStopIndex": 11,
"visibleColumnStartIndex": 2,
"visibleColumnStopIndex": 5,
"visibleRowStartIndex": 8,
"visibleRowStopIndex": 10,
},
],
Array [
Object {
"overscanColumnStartIndex": 0,
"overscanColumnStopIndex": 4,
"overscanRowStartIndex": 7,
"overscanRowStopIndex": 11,
"visibleColumnStartIndex": 0,
"visibleColumnStopIndex": 3,
"visibleRowStartIndex": 8,
"visibleRowStopIndex": 10,
},
],
]
`;

Expand Down Expand Up @@ -91,6 +115,30 @@ Array [
"visibleRowStopIndex": 19,
},
],
Array [
Object {
"overscanColumnStartIndex": 5,
"overscanColumnStopIndex": 9,
"overscanRowStartIndex": 8,
"overscanRowStopIndex": 12,
"visibleColumnStartIndex": 6,
"visibleColumnStopIndex": 9,
"visibleRowStartIndex": 9,
"visibleRowStopIndex": 11,
},
],
Array [
Object {
"overscanColumnStartIndex": 0,
"overscanColumnStopIndex": 6,
"overscanRowStartIndex": 8,
"overscanRowStopIndex": 12,
"visibleColumnStartIndex": 1,
"visibleColumnStopIndex": 5,
"visibleRowStartIndex": 9,
"visibleRowStopIndex": 11,
},
],
]
`;

Expand Down Expand Up @@ -144,6 +192,30 @@ Array [
"visibleRowStopIndex": 3,
},
],
Array [
Object {
"overscanColumnStartIndex": 0,
"overscanColumnStopIndex": 4,
"overscanRowStartIndex": 7,
"overscanRowStopIndex": 11,
"visibleColumnStartIndex": 0,
"visibleColumnStopIndex": 3,
"visibleRowStartIndex": 8,
"visibleRowStopIndex": 10,
},
],
Array [
Object {
"overscanColumnStartIndex": 5,
"overscanColumnStopIndex": 9,
"overscanRowStartIndex": 7,
"overscanRowStopIndex": 11,
"visibleColumnStartIndex": 6,
"visibleColumnStopIndex": 9,
"visibleRowStartIndex": 8,
"visibleRowStopIndex": 10,
},
],
]
`;

Expand Down Expand Up @@ -197,5 +269,29 @@ Array [
"visibleRowStopIndex": 19,
},
],
Array [
Object {
"overscanColumnStartIndex": 5,
"overscanColumnStopIndex": 9,
"overscanRowStartIndex": 9,
"overscanRowStopIndex": 13,
"visibleColumnStartIndex": 6,
"visibleColumnStopIndex": 9,
"visibleRowStartIndex": 10,
"visibleRowStopIndex": 12,
},
],
Array [
Object {
"overscanColumnStartIndex": 0,
"overscanColumnStopIndex": 4,
"overscanRowStartIndex": 9,
"overscanRowStopIndex": 13,
"visibleColumnStartIndex": 0,
"visibleColumnStopIndex": 3,
"visibleRowStartIndex": 10,
"visibleRowStopIndex": 12,
},
],
]
`;
42 changes: 24 additions & 18 deletions src/createGridComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ export default function createGridComponent({
rowIndex,
}: {
align: ScrollToAlign,
columnIndex: number,
rowIndex: number,
columnIndex?: number,
rowIndex?: number,
}): void {
const { height, width } = this.props;
const { scrollLeft, scrollTop } = this.state;
Expand All @@ -272,22 +272,28 @@ export default function createGridComponent({
estimatedTotalHeight > height ? scrollbarSize : 0;

this.scrollTo({
scrollLeft: getOffsetForColumnAndAlignment(
this.props,
columnIndex,
align,
scrollLeft,
this._instanceProps,
verticalScrollbarSize
),
scrollTop: getOffsetForRowAndAlignment(
this.props,
rowIndex,
align,
scrollTop,
this._instanceProps,
horizontalScrollbarSize
),
scrollLeft:
columnIndex !== undefined
? getOffsetForColumnAndAlignment(
this.props,
columnIndex,
align,
scrollLeft,
this._instanceProps,
verticalScrollbarSize
)
: scrollLeft,
scrollTop:
rowIndex !== undefined
? getOffsetForRowAndAlignment(
this.props,
rowIndex,
align,
scrollTop,
this._instanceProps,
horizontalScrollbarSize
)
: scrollTop,
});
}

Expand Down
Loading