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] Fix error when using columnGrouping with all columns hidden #6425

Merged
merged 1 commit into from Oct 7, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -330,7 +330,7 @@ export const useGridColumnHeaders = (props: UseGridColumnHeadersProps) => {
}
const columnsToRender = getColumnsToRender(params);

if (columnsToRender == null) {
if (columnsToRender == null || columnsToRender.renderedColumns.length === 0) {
return null;
}

Expand Down
Expand Up @@ -50,7 +50,7 @@ describe('<DataGrid /> - Column grouping', () => {
expect(screen.queryAllByRole('row')).to.have.length(3);
});

it('should add header rows to match max depth oc column groups', () => {
it('should add header rows to match max depth of column groups', () => {
render(
<TestDataGrid
nbColumns={3}
Expand Down Expand Up @@ -261,6 +261,31 @@ describe('<DataGrid /> - Column grouping', () => {
Array.from(row2Headers).map((header) => header.getAttribute('aria-colindex')),
).to.deep.equal(['1', '3']);
});

it('should not throw warning when all columns are hidden', () => {
const { setProps } = render(
<TestDataGrid
nbColumns={3}
columnGroupingModel={[
{
groupId: 'col123',
children: [
{ groupId: 'A', children: [{ field: 'col1' }, { field: 'col2' }] },
{ field: 'col3' },
],
},
]}
/>,
);

setProps({
columnVisibilityModel: {
col1: false,
col2: false,
col3: false,
},
});
});
});

// TODO: remove the skip. I failed to test if an error is thrown
Expand Down