Skip to content

Commit 224ba41

Browse files
romgrkthomasmoon
authored andcommitted
[DataGridPro] Keep bottom pinned row at the bottom (mui#13313)
1 parent 0f86246 commit 224ba41

File tree

11 files changed

+120
-58
lines changed

11 files changed

+120
-58
lines changed

packages/x-data-grid-premium/src/tests/clipboard.DataGridPremium.test.tsx

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,14 @@ describe('<DataGridPremium /> - Clipboard', () => {
119119
{ id: 2, brand: 'Puma' },
120120
];
121121
render(
122-
<DataGridPremium
123-
columns={columns}
124-
rows={rows}
125-
cellSelection
126-
sortModel={[{ field: 'brand', sort: 'asc' }]}
127-
/>,
122+
<div style={{ width: 300, height: 300 }}>
123+
<DataGridPremium
124+
columns={columns}
125+
rows={rows}
126+
cellSelection
127+
sortModel={[{ field: 'brand', sort: 'asc' }]}
128+
/>
129+
</div>,
128130
);
129131

130132
const cell = getCell(0, 0);
@@ -143,15 +145,17 @@ describe('<DataGridPremium /> - Clipboard', () => {
143145

144146
it('should not escape double quotes when copying multiple cells to clipboard', () => {
145147
render(
146-
<DataGridPremium
147-
columns={[{ field: 'value' }]}
148-
rows={[
149-
{ id: 0, value: '1 " 1' },
150-
{ id: 1, value: '2' },
151-
]}
152-
cellSelection
153-
disableRowSelectionOnClick
154-
/>,
148+
<div style={{ width: 300, height: 300 }}>
149+
<DataGridPremium
150+
columns={[{ field: 'value' }]}
151+
rows={[
152+
{ id: 0, value: '1 " 1' },
153+
{ id: 1, value: '2' },
154+
]}
155+
cellSelection
156+
disableRowSelectionOnClick
157+
/>
158+
</div>,
155159
);
156160

157161
const cell = getCell(0, 0);

packages/x-data-grid-pro/src/tests/pagination.DataGridPro.test.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ describe('<DataGridPro /> - Pagination', () => {
105105

106106
it('should log an error if rowCount is used with client-side pagination', () => {
107107
expect(() => {
108-
render(<DataGridPro rows={[]} columns={[]} paginationMode="client" rowCount={100} />);
108+
render(
109+
<div style={{ width: 300, height: 300 }}>
110+
<DataGridPro rows={[]} columns={[]} paginationMode="client" rowCount={100} />
111+
</div>,
112+
);
109113
}).toErrorDev([
110114
'MUI X: Usage of the `rowCount` prop with client side pagination (`paginationMode="client"`) has no effect. `rowCount` is only meant to be used with `paginationMode="server"`.',
111115
]);

packages/x-data-grid/src/components/base/GridOverlays.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ function GridOverlayWrapper(props: React.PropsWithChildren<GridOverlaysProps>) {
6969

7070
let height: React.CSSProperties['height'] =
7171
dimensions.viewportOuterSize.height -
72-
dimensions.headersTotalHeight -
72+
dimensions.topContainerHeight -
73+
dimensions.bottomContainerHeight -
7374
(dimensions.hasScrollX ? dimensions.scrollbarSize : 0);
7475

7576
if ((rootProps.autoHeight && currentPage.rows.length === 0) || height === 0) {

packages/x-data-grid/src/components/virtualization/GridVirtualScroller.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function GridVirtualScroller(props: GridVirtualScrollerProps) {
106106
</RenderZone>
107107
</Content>
108108

109-
{rows.length > 0 && <SpaceFiller />}
109+
<SpaceFiller rowsLength={rows.length} />
110110

111111
<BottomContainer>
112112
<rootProps.slots.pinnedRows position="bottom" virtualScroller={virtualScroller} />

packages/x-data-grid/src/components/virtualization/GridVirtualScrollerFiller.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,29 @@ const Pinned = styled('div')({
1717
position: 'sticky',
1818
height: '100%',
1919
boxSizing: 'border-box',
20-
borderTop: '1px solid var(--DataGrid-rowBorderColor)',
20+
borderTop: '1px solid var(--rowBorderColor)',
2121
backgroundColor: 'var(--DataGrid-pinnedBackground)',
2222
});
2323
const PinnedLeft = styled(Pinned)({
2424
left: 0,
25-
borderRight: '1px solid var(--DataGrid-rowBorderColor)',
25+
borderRight: '1px solid var(--rowBorderColor)',
2626
});
2727
const PinnedRight = styled(Pinned)({
2828
right: 0,
29-
borderLeft: '1px solid var(--DataGrid-rowBorderColor)',
29+
borderLeft: '1px solid var(--rowBorderColor)',
3030
});
3131

3232
const Main = styled('div')({
3333
flexGrow: 1,
34-
borderTop: '1px solid var(--DataGrid-rowBorderColor)',
34+
borderTop: '1px solid var(--rowBorderColor)',
3535
});
3636

37-
function GridVirtualScrollerFiller() {
37+
type Props = {
38+
/** The number of rows */
39+
rowsLength: number;
40+
};
41+
42+
function GridVirtualScrollerFiller({ rowsLength }: Props) {
3843
const apiRef = useGridApiContext();
3944
const {
4045
viewportOuterSize,
@@ -54,7 +59,16 @@ function GridVirtualScrollerFiller() {
5459
}
5560

5661
return (
57-
<Filler className={gridClasses.filler} role="presentation" style={{ height }}>
62+
<Filler
63+
className={gridClasses.filler}
64+
role="presentation"
65+
style={
66+
{
67+
height,
68+
'--rowBorderColor': rowsLength === 0 ? 'transparent' : 'var(--DataGrid-rowBorderColor)',
69+
} as React.CSSProperties
70+
}
71+
>
5872
{leftPinnedWidth > 0 && (
5973
<PinnedLeft
6074
className={gridClasses['filler--pinnedLeft']}

packages/x-data-grid/src/hooks/features/virtualization/useGridVirtualScroller.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -517,22 +517,13 @@ export const useGridVirtualScroller = () => {
517517
);
518518

519519
const contentSize = React.useMemo(() => {
520-
// In cases where the columns exceed the available width,
521-
// the horizontal scrollbar should be shown even when there're no rows.
522-
// Keeping 1px as minimum height ensures that the scrollbar will visible if necessary.
523-
const height = Math.max(contentHeight, 1);
524-
525520
const size: React.CSSProperties = {
526521
width: needsHorizontalScrollbar ? columnsTotalWidth : 'auto',
527-
height,
522+
height: contentHeight,
528523
};
529524

530-
if (rootProps.autoHeight) {
531-
if (currentPage.rows.length === 0) {
532-
size.height = getMinimalContentHeight(apiRef); // Give room to show the overlay when there no rows.
533-
} else {
534-
size.height = contentHeight;
535-
}
525+
if (rootProps.autoHeight && currentPage.rows.length === 0) {
526+
size.height = getMinimalContentHeight(apiRef); // Give room to show the overlay when there no rows.
536527
}
537528

538529
return size;

packages/x-data-grid/src/tests/DataGrid.test.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,21 @@ describe('<DataGrid />', () => {
7676
];
7777
expect(() => {
7878
render(
79-
<DataGrid
80-
{...(
81-
Object.keys(DATA_GRID_PROPS_DEFAULT_VALUES) as Array<
82-
keyof typeof DATA_GRID_PROPS_DEFAULT_VALUES
83-
>
84-
).reduce((acc, key) => {
85-
// @ts-ignore
86-
acc[key] = undefined;
87-
return acc;
88-
}, {})}
89-
rows={rows}
90-
columns={columns}
91-
/>,
79+
<div style={{ height: 300, width: 300 }}>
80+
<DataGrid
81+
{...(
82+
Object.keys(DATA_GRID_PROPS_DEFAULT_VALUES) as Array<
83+
keyof typeof DATA_GRID_PROPS_DEFAULT_VALUES
84+
>
85+
).reduce((acc, key) => {
86+
// @ts-ignore
87+
acc[key] = undefined;
88+
return acc;
89+
}, {})}
90+
rows={rows}
91+
columns={columns}
92+
/>
93+
</div>,
9294
);
9395
}).not.toErrorDev();
9496
});

packages/x-data-grid/src/tests/layout.DataGrid.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ describe('<DataGrid /> - Layout & warnings', () => {
11741174
}
11751175

11761176
render(
1177-
<div style={{ height: '100%', width: 400.6 }}>
1177+
<div style={{ height: 300, width: 400.6 }}>
11781178
<DataGrid rows={[{ id: 1 }]} columns={[{ field: 'id', flex: 1 }]} />
11791179
</div>,
11801180
);
@@ -1213,7 +1213,7 @@ describe('<DataGrid /> - Layout & warnings', () => {
12131213
}
12141214

12151215
render(
1216-
<div style={{ height: 'auto', width: 1584 }}>
1216+
<div style={{ height: 300, width: 1584 }}>
12171217
<DataGrid
12181218
rows={[{ id: 1 }]}
12191219
columns={[

packages/x-data-grid/src/tests/pagination.DataGrid.test.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -730,12 +730,14 @@ describe('<DataGrid /> - Pagination', () => {
730730
];
731731
expect(() => {
732732
const { setProps } = render(
733-
<DataGrid
734-
columns={columns}
735-
rows={rows}
736-
initialState={{ pagination: { paginationModel: { pageSize: 2, page: 1 } } }}
737-
pageSizeOptions={[2]}
738-
/>,
733+
<div style={{ width: 300, height: 300 }}>
734+
<DataGrid
735+
columns={columns}
736+
rows={rows}
737+
initialState={{ pagination: { paginationModel: { pageSize: 2, page: 1 } } }}
738+
pageSizeOptions={[2]}
739+
/>
740+
</div>,
739741
);
740742
setProps({ rows: rows.slice(0, 2) });
741743
}).not.to.throw();

test/karma.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const webpack = require('webpack');
33

44
const CI = Boolean(process.env.CI);
55

6-
process.env.CHROME_BIN = chromium.executablePath();
6+
process.env.CHROME_BIN ||= chromium.executablePath();
77

88
// Karma configuration
99
module.exports = function setKarmaConfig(config) {

0 commit comments

Comments
 (0)