Skip to content

Commit

Permalink
[DataGridPremium] Fix leafField to have correct focus value (#7950)
Browse files Browse the repository at this point in the history
  • Loading branch information
MBilalShafi authored Feb 16, 2023
1 parent 39190c7 commit c120409
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export const createGroupingColDefForOneGroupingCriteria = ({
const leafParams: GridRenderCellParams = {
...params.api.getCellParams(params.id, leafField!),
api: params.api,
hasFocus: params.hasFocus,
};
if (leafColDef.renderCell) {
return leafColDef.renderCell(leafParams);
Expand Down Expand Up @@ -308,6 +309,7 @@ export const createGroupingColDefForAllGroupingCriteria = ({
const leafParams: GridRenderCellParams = {
...params.api.getCellParams(params.id, leafField!),
api: params.api,
hasFocus: params.hasFocus,
};
if (leafColDef.renderCell) {
return leafColDef.renderCell(leafParams);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as React from 'react';
// @ts-ignore Remove once the test utils are typed
import { createRenderer, fireEvent, screen, act } from '@mui/monorepo/test/utils';
import { createRenderer, fireEvent, screen, act, userEvent } from '@mui/monorepo/test/utils';
import {
getColumnHeaderCell,
getColumnHeadersTextContent,
getColumnValues,
getCell,
} from 'test/utils/helperFn';
import { expect } from 'chai';
import {
Expand Down Expand Up @@ -814,6 +815,33 @@ describe('<DataGridPremium /> - Row Grouping', () => {
'Custom leaf',
]);
});

// See https://github.com/mui/mui-x/issues/7949
it('should correctly pass `hasFocus` to `renderCell` defined on the leafColDef', () => {
const renderIdCell = spy((params) => `Focused: ${params.hasFocus}`);

render(
<Test
columns={[
{
field: 'id',
type: 'number',
renderCell: renderIdCell,
},
{
field: 'category1',
},
]}
initialState={{ rowGrouping: { model: ['category1'] } }}
groupingColDef={{ leafField: 'id' }}
defaultGroupingExpansionDepth={-1}
/>,
);

userEvent.mousePress(getCell(1, 0));
expect(renderIdCell.lastCall.firstArg.field).to.equal('id');
expect(getCell(1, 0)).to.have.text('Focused: true');
});
});

describe('prop: groupColDef.headerName', () => {
Expand Down

0 comments on commit c120409

Please sign in to comment.