Skip to content

Commit

Permalink
[DataGridPro] Fix onRowsScrollEnd being triggered instantly when us…
Browse files Browse the repository at this point in the history
…ing a bottom pinned row (#14602)
  • Loading branch information
arminmeh authored Sep 13, 2024
1 parent db33905 commit d64e377
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,52 @@ describe('<DataGridPro /> - Infnite loader', () => {
// should not load more rows because the threshold is not reached
expect(getRow.callCount).to.equal(5);
});

it('should not call `onRowsScrollEnd` if there are rows pinned to the bottom and the viewport scroll is at the top', async function test() {
if (isJSDOM) {
this.skip(); // Needs layout
}
const baseRows = [
{ id: 0, brand: 'Nike' },
{ id: 1, brand: 'Adidas' },
{ id: 2, brand: 'Puma' },
{ id: 3, brand: 'Under Armor' },
{ id: 4, brand: 'Jordan' },
{ id: 5, brand: 'Reebok' },
];
const basePinnedRows = {
bottom: [{ id: 6, brand: 'Unbranded' }],
};

const handleRowsScrollEnd = spy();
function TestCase({
rows,
pinnedRows,
}: {
rows: typeof baseRows;
pinnedRows: typeof basePinnedRows;
}) {
return (
<div style={{ width: 300, height: 300 }}>
<DataGridPro
columns={[{ field: 'brand', width: 100 }]}
rows={rows}
onRowsScrollEnd={handleRowsScrollEnd}
pinnedRows={pinnedRows}
/>
</div>
);
}
const { container } = render(<TestCase rows={baseRows} pinnedRows={basePinnedRows} />);
const virtualScroller = container.querySelector('.MuiDataGrid-virtualScroller')!;
await sleep(1);
// after initial render and a scroll event that did not reach the bottom of the grid
// the `onRowsScrollEnd` should not be called
expect(handleRowsScrollEnd.callCount).to.equal(0);
// arbitrary number to make sure that the bottom of the grid window is reached.
virtualScroller.scrollTop = 12345;
virtualScroller.dispatchEvent(new Event('scroll'));
await sleep(1);
expect(handleRowsScrollEnd.callCount).to.equal(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ export const useGridVirtualScroller = () => {
if (panel) {
rows.push(panel);
}
if (isLastVisible) {
if (params.position === undefined && isLastVisibleInSection) {
rows.push(apiRef.current.getInfiniteLoadingTriggerElement?.({ lastRowId: id }));
}
});
Expand Down

0 comments on commit d64e377

Please sign in to comment.