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

[DataGrid] Fix row click propagation causing error in nested grid #9741

Merged
merged 2 commits into from
Jul 21, 2023
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
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 @@ -247,7 +247,7 @@ const GridRow = React.forwardRef<HTMLDivElement, GridRowProps>(function GridRow(

// User clicked a button from the "actions" column type
const column = apiRef.current.getColumn(field);
if (column.type === GRID_ACTIONS_COLUMN_TYPE) {
if (column?.type === GRID_ACTIONS_COLUMN_TYPE) {
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ export const useGridRowSelection = (
if (field) {
const column = apiRef.current.getColumn(field);

if (column.type === GRID_ACTIONS_COLUMN_TYPE) {
if (column?.type === GRID_ACTIONS_COLUMN_TYPE) {
return;
}
}
Expand Down
39 changes: 39 additions & 0 deletions packages/grid/x-data-grid/src/tests/rows.DataGrid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
} from '@mui/x-data-grid';
import { getBasicGridData } from '@mui/x-data-grid-generator';
import { getColumnValues, getRow, getActiveCell, getCell } from 'test/utils/helperFn';
import Dialog from '@mui/material/Dialog';

import { COMPACT_DENSITY_FACTOR } from '../hooks/features/density/useGridDensity';

const isJSDOM = /jsdom/.test(window.navigator.userAgent);
Expand Down Expand Up @@ -122,6 +124,43 @@ describe('<DataGrid /> - Rows', () => {
expect(handleRowClick.callCount).to.equal(1);
});

// https://github.com/mui/mui-x/issues/8042
it('should not throw when clicking the cell in the nested grid in a portal', () => {
const rows = [
{ id: 1, firstName: 'Jon', age: 35 },
{ id: 2, firstName: 'Cersei', age: 42 },
{ id: 3, firstName: 'Jaime', age: 45 },
];

function NestedGridDialog() {
return (
<Dialog open>
<div style={{ height: 300, width: '100%' }}>
<DataGrid rows={rows} columns={[{ field: 'id' }, { field: 'age' }]} />
</div>
</Dialog>
);
}

expect(() => {
render(
<div style={{ width: 300, height: 300 }}>
<DataGrid
columns={[
{ field: 'id' },
{ field: 'firstName', renderCell: () => <NestedGridDialog /> },
]}
rows={rows}
/>
</div>,
);

// click on the cell in the nested grid in the column that is not defined in the parent grid
const cell = document.querySelector('[data-rowindex="0"] [role="cell"][data-field="age"]')!;
fireEvent.click(cell);
}).not.toErrorDev();
});

describe('prop: getRowClassName', () => {
it('should apply the CSS class returned by getRowClassName', () => {
const getRowId: GridRowIdGetter = (row) => `${row.clientId}`;
Expand Down