Skip to content

Commit b7e10e7

Browse files
authored
[DataGrid] Merge row styles with componentsProps.row.style (#7641)
Resolves #6846
1 parent 18b8f60 commit b7e10e7

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

packages/grid/x-data-grid-pro/src/tests/detailPanel.DataGridPro.test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,4 +653,22 @@ describe('<DataGridPro /> - Detail panel', () => {
653653
});
654654
});
655655
});
656+
657+
it('should merge row styles when expanded', () => {
658+
render(
659+
<TestCase
660+
getDetailPanelHeight={() => 0}
661+
nbRows={1}
662+
getDetailPanelContent={() => <div />}
663+
componentsProps={{
664+
row: { style: { color: 'yellow' } },
665+
}}
666+
/>,
667+
);
668+
fireEvent.click(screen.getByRole('button', { name: 'Expand' }));
669+
expect(getRow(0)).toHaveInlineStyle({
670+
color: 'yellow',
671+
marginBottom: '0px', // added when expanded
672+
});
673+
});
656674
});

packages/grid/x-data-grid/src/hooks/features/virtualization/useGridVirtualScroller.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,10 @@ export const useGridVirtualScroller = (props: UseGridVirtualScrollerProps) => {
492492
isSelected = apiRef.current.isRowSelectable(id);
493493
}
494494

495+
const { style: rootRowStyle, ...rootRowProps } = rootProps.componentsProps?.row || {};
496+
const { style: rowStyle, ...rowProps } =
497+
(typeof getRowProps === 'function' && getRowProps(id, model)) || {};
498+
495499
rows.push(
496500
<rootProps.components.Row
497501
key={id}
@@ -510,8 +514,12 @@ export const useGridVirtualScroller = (props: UseGridVirtualScrollerProps) => {
510514
containerWidth={availableSpace}
511515
isLastVisible={lastVisibleRowIndex}
512516
position={position}
513-
{...(typeof getRowProps === 'function' ? getRowProps(id, model) : {})}
514-
{...rootProps.componentsProps?.row}
517+
{...rowProps}
518+
{...rootRowProps}
519+
style={{
520+
...rowStyle,
521+
...rootRowStyle,
522+
}}
515523
/>,
516524
);
517525
}

0 commit comments

Comments
 (0)