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] Support style prop #2116

Merged
merged 3 commits into from
Jul 12, 2021
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
4 changes: 4 additions & 0 deletions packages/grid/_modules_/grid/GridComponentProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,8 @@ export interface GridComponentProps extends GridOptionsProp {
* Set the whole state of the grid.
*/
state?: Partial<GridState>;
/**
* @ignore
*/
style?: React.CSSProperties;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const GridRoot = React.forwardRef<HTMLDivElement, GridRootProps>(function
const classes = useStyles();
const apiRef = useGridApiContext();
const rootProps = React.useContext(GridRootPropsContext)!;
const { className } = rootProps;
const { children, className: classNameProp, ...other } = props;
const visibleColumnsLength = useGridSelector(apiRef, visibleGridColumnsLengthSelector);
const [gridState] = useGridState(apiRef!);
Expand All @@ -33,7 +32,7 @@ export const GridRoot = React.forwardRef<HTMLDivElement, GridRootProps>(function
<NoSsr>
<div
ref={handleRef}
className={clsx(classes.root, options.classes?.root, className, classNameProp, {
className={clsx(classes.root, options.classes?.root, rootProps.className, classNameProp, {
'MuiDataGrid-autoHeight': gridState.options.autoHeight,
})}
role="grid"
Expand All @@ -42,6 +41,7 @@ export const GridRoot = React.forwardRef<HTMLDivElement, GridRootProps>(function
aria-multiselectable={!gridState.options.disableMultipleSelection}
aria-label={rootProps['aria-label']}
aria-labelledby={rootProps['aria-labelledby']}
style={rootProps.style}
{...other}
>
{children}
Expand Down
21 changes: 20 additions & 1 deletion packages/grid/x-grid/src/tests/layout.XGrid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,26 @@ describe('<XGrid /> - Layout', () => {
</div>,
);

expect(document.querySelector(`.${className}`)).to.equal(container.firstChild.firstChild);
expect(container.firstChild.firstChild).to.have.class(className);
expect(container.firstChild.firstChild).to.have.class('MuiDataGrid-root');
});

it('applies the style to the root component', () => {
render(
<div style={{ width: 300, height: 300 }}>
<XGrid
{...baselineProps}
style={{
mixBlendMode: 'darken',
}}
/>
</div>,
);

// @ts-expect-error need to migrate helpers to TypeScript
expect(document.querySelector('.MuiDataGrid-root')).toHaveInlineStyle({
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't use the role="grid" because I trust more that we set the root class name on the root than the aria.

mixBlendMode: 'darken',
});
});
});
});