Skip to content

Commit

Permalink
[DataGrid] Merge row styles with componentsProps.row.style (#7641)
Browse files Browse the repository at this point in the history
Resolves #6846
  • Loading branch information
marktoman authored Jan 30, 2023
1 parent 18b8f60 commit b7e10e7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -653,4 +653,22 @@ describe('<DataGridPro /> - Detail panel', () => {
});
});
});

it('should merge row styles when expanded', () => {
render(
<TestCase
getDetailPanelHeight={() => 0}
nbRows={1}
getDetailPanelContent={() => <div />}
componentsProps={{
row: { style: { color: 'yellow' } },
}}
/>,
);
fireEvent.click(screen.getByRole('button', { name: 'Expand' }));
expect(getRow(0)).toHaveInlineStyle({
color: 'yellow',
marginBottom: '0px', // added when expanded
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,10 @@ export const useGridVirtualScroller = (props: UseGridVirtualScrollerProps) => {
isSelected = apiRef.current.isRowSelectable(id);
}

const { style: rootRowStyle, ...rootRowProps } = rootProps.componentsProps?.row || {};
const { style: rowStyle, ...rowProps } =
(typeof getRowProps === 'function' && getRowProps(id, model)) || {};

rows.push(
<rootProps.components.Row
key={id}
Expand All @@ -510,8 +514,12 @@ export const useGridVirtualScroller = (props: UseGridVirtualScrollerProps) => {
containerWidth={availableSpace}
isLastVisible={lastVisibleRowIndex}
position={position}
{...(typeof getRowProps === 'function' ? getRowProps(id, model) : {})}
{...rootProps.componentsProps?.row}
{...rowProps}
{...rootRowProps}
style={{
...rowStyle,
...rootRowStyle,
}}
/>,
);
}
Expand Down

0 comments on commit b7e10e7

Please sign in to comment.