Skip to content

Commit c351ce4

Browse files
committed
Fix <Datagrid> does not apply className to its root element
1 parent 4eb4f4c commit c351ce4

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

packages/ra-ui-materialui/src/list/datagrid/Datagrid.stories.tsx

+31-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
useGetList,
1010
useList,
1111
} from 'ra-core';
12-
import { Box } from '@mui/material';
12+
import { Box, styled } from '@mui/material';
1313
import { createTheme, ThemeProvider } from '@mui/material/styles';
1414

1515
import { TextField } from '../../field';
@@ -381,3 +381,33 @@ export const IsRowExpandable = () => (
381381
</Datagrid>
382382
</Wrapper>
383383
);
384+
385+
const StyledDatagrid = styled(Datagrid, {
386+
name: 'MyStyledDatagrid',
387+
overridesResolver: (props, styles) => styles.root,
388+
})(() => ({
389+
width: '70%',
390+
backgroundColor: '#ffb',
391+
}));
392+
393+
export const StyledComponent = () => (
394+
<Wrapper>
395+
<Datagrid
396+
sx={{
397+
width: '70%',
398+
backgroundColor: '#ffb',
399+
}}
400+
>
401+
<TextField source="id" />
402+
<TextField source="title" />
403+
<TextField source="author" />
404+
<TextField source="year" />
405+
</Datagrid>
406+
<StyledDatagrid>
407+
<TextField source="id" />
408+
<TextField source="title" />
409+
<TextField source="author" />
410+
<TextField source="year" />
411+
</StyledDatagrid>
412+
</Wrapper>
413+
);

packages/ra-ui-materialui/src/list/datagrid/Datagrid.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,10 @@ export const Datagrid: FC<DatagridProps> = React.forwardRef((props, ref) => {
228228
*/
229229
return (
230230
<DatagridContextProvider value={contextValue}>
231-
<DatagridRoot sx={sx} className={DatagridClasses.root}>
231+
<DatagridRoot
232+
sx={sx}
233+
className={clsx(DatagridClasses.root, className)}
234+
>
232235
{bulkActionButtons !== false ? (
233236
<BulkActionsToolbar selectedIds={selectedIds}>
234237
{isValidElement(bulkActionButtons)
@@ -239,7 +242,7 @@ export const Datagrid: FC<DatagridProps> = React.forwardRef((props, ref) => {
239242
<div className={DatagridClasses.tableWrapper}>
240243
<Table
241244
ref={ref}
242-
className={clsx(DatagridClasses.table, className)}
245+
className={DatagridClasses.table}
243246
size={size}
244247
{...sanitizeRestProps(rest)}
245248
>

0 commit comments

Comments
 (0)