Skip to content

Commit

Permalink
fix mui#821 custom footer not hiding on hideFooter
Browse files Browse the repository at this point in the history
  • Loading branch information
dtassone committed Jan 12, 2021
1 parent 2b74a22 commit 8964ced
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 16 deletions.
26 changes: 14 additions & 12 deletions packages/grid/_modules_/grid/GridComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,20 @@ export const GridComponent = React.forwardRef<HTMLDivElement, GridComponentProps
</GridDataContainer>
</GridWindow>
</div>
<div ref={footerRef}>
{customComponents.footerComponent || (
<DefaultFooter
paginationComponent={
!!gridState.options.pagination &&
gridState.pagination.pageSize != null &&
!gridState.options.hideFooterPagination &&
(customComponents.paginationComponent || <Pagination />)
}
/>
)}
</div>
{!gridState.options.hideFooter && (
<div ref={footerRef}>
{customComponents.footerComponent || (
<DefaultFooter
paginationComponent={
!!gridState.options.pagination &&
gridState.pagination.pageSize != null &&
!gridState.options.hideFooterPagination &&
(customComponents.paginationComponent || <Pagination />)
}
/>
)}
</div>
)}
</ErrorBoundary>
</ApiContext.Provider>
</GridRoot>
Expand Down
4 changes: 0 additions & 4 deletions packages/grid/_modules_/grid/components/DefaultFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ export const DefaultFooter = React.forwardRef<HTMLDivElement, DefaultFooterProps
const options = useGridSelector(apiRef, optionsSelector);
const selectedRowCount = useGridSelector(apiRef, selectedRowsCountSelector);

if (options.hideFooter) {
return null;
}

const showSelectedRowCount =
!options.hideFooterSelectedRowCount && selectedRowCount > 0 ? (
<SelectedRowCount selectedRowCount={selectedRowCount} />
Expand Down
55 changes: 55 additions & 0 deletions packages/grid/data-grid/src/tests/components.DataGrid.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import * as React from 'react';
import { createClientRenderStrictMode } from 'test/utils';
import { expect } from 'chai';
import { DataGrid } from '@material-ui/data-grid';

describe('<DataGrid /> - Components', () => {
// TODO v5: replace with createClientRender
const render = createClientRenderStrictMode();

const baselineProps = {
rows: [
{
id: 0,
brand: 'Nike',
},
{
id: 1,
brand: 'Adidas',
},
{
id: 2,
brand: 'Puma',
},
],
columns: [{ field: 'brand' }],
};

describe('footer', () => {
before(function beforeHook() {
if (/jsdom/.test(window.navigator.userAgent)) {
// Need layouting
this.skip();
}
});

it('should hide footer if prop hideFooter is set', () => {
render(
<div style={{ width: 300, height: 500 }}>
<DataGrid {...baselineProps} hideFooter />
</div>,
);
expect(document.querySelectorAll('.MuiDataGrid-footer').length).to.equal(0);
});

it('should hide custom footer if prop hideFooter is set', () => {
const CustomFooter = () => <div className="customFooter">Custom Footer</div>;
render(
<div style={{ width: 300, height: 500 }}>
<DataGrid {...baselineProps} hideFooter components={{ footer: CustomFooter }} />
</div>,
);
expect(document.querySelectorAll('.customFooter').length).to.equal(0);
});
});
});

0 comments on commit 8964ced

Please sign in to comment.