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

[DataGridPro] Fix crash when using pinnedRows + getRowClassName props and rows=[] #5851

Merged
merged 2 commits into from
Aug 25, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -765,4 +765,15 @@ describe('<DataGridPro /> - Row pinning', () => {

expect(screen.getByRole('grid').getAttribute('aria-rowcount')).to.equal(`${rowCount + 1}`); // +1 for header row
});

// https://github.com/mui/mui-x/issues/5845
it('should work with `getCellClassName` when `rows=[]`', () => {
const className = 'test-class-name';
render(
<BaselineTestCase rowCount={2} colCount={1} rows={[]} getRowClassName={() => className} />,
);

expect(getRowById(0)!.classList.contains(className)).to.equal(true);
expect(getRowById(1)!.classList.contains(className)).to.equal(true);
Comment on lines +776 to +777
Copy link
Member

Choose a reason for hiding this comment

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

Much simpler.

Suggested change
expect(getRowById(0)!.classList.contains(className)).to.equal(true);
expect(getRowById(1)!.classList.contains(className)).to.equal(true);
expect(getRowById(0)!).to.have.class(className);
expect(getRowById(1)!).to.have.class(className);

Copy link
Member Author

Choose a reason for hiding this comment

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

I did this intentionally to have meaningful error message when test fails.
See #3607 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

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

I've commented the related issue in mocha: mochajs/mocha#4910

Copy link
Member

Choose a reason for hiding this comment

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

Once mocha fixes this issue we can use the other syntax here, keeping the same convention like other tests.

});
});
2 changes: 1 addition & 1 deletion packages/grid/x-data-grid/src/components/GridRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ function GridRow(props: React.HTMLAttributes<HTMLDivElement> & GridRowProps) {
let rowClassName: string | null = null;

if (typeof rootProps.getRowClassName === 'function') {
const indexRelativeToCurrentPage = index - currentPage.range!.firstRowIndex;
const indexRelativeToCurrentPage = index - (currentPage.range?.firstRowIndex || 0);
const rowParams: GridRowClassNameParams = {
...apiRef.current.getRowParams(rowId),
isFirstVisible: indexRelativeToCurrentPage === 0,
Expand Down