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] Spread forwardedProps onto grid element #14197

Closed
Closed
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
8 changes: 1 addition & 7 deletions packages/x-data-grid/src/DataGrid/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,7 @@ const DataGridRaw = React.forwardRef(function DataGrid<R extends GridValidRowMod
}
return (
<GridContextProvider privateApiRef={privateApiRef} configuration={configuration} props={props}>
<GridRoot
className={props.className}
style={props.style}
sx={props.sx}
ref={ref}
{...props.forwardedProps}
>
<GridRoot className={props.className} style={props.style} sx={props.sx} ref={ref}>
<GridHeader />
<GridBody />
<GridFooterPlaceholder />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const GridMainContainer = React.forwardRef<
className={props.className}
tabIndex={-1}
{...ariaAttributes}
{...rootProps.forwardedProps}
>
<GridPanelAnchor role="presentation" data-id="gridPanelAnchor" />
{props.children}
Expand Down
7 changes: 3 additions & 4 deletions packages/x-data-grid/src/tests/DataGrid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,20 @@ describe('<DataGrid />', () => {
};

it('should accept aria & data attributes props', () => {
const gridRef = React.createRef<HTMLDivElement>();
render(
<div style={{ width: 300, height: 500 }}>
<DataGrid
{...baselineProps}
ref={gridRef}
columns={[{ field: 'brand' }]}
data-custom-id="grid-1"
aria-label="Grid one"
/>
</div>,
);

expect(document.querySelector('[data-custom-id="grid-1"]')).to.equal(gridRef.current);
expect(document.querySelector('[aria-label="Grid one"]')).to.equal(gridRef.current);
const gridElement = document.querySelector<HTMLElement>(`[role="grid"]`);
expect(gridElement!.getAttribute('data-custom-id')).to.equal('grid-1');
expect(gridElement!.getAttribute('aria-label')).to.equal('Grid one');
});

it('should not fail when row have IDs match Object prototype keys (constructor, hasOwnProperty, etc)', () => {
Expand Down
Loading