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] Remove GridCell borderBottom when last row #3519

Merged
Merged
2 changes: 2 additions & 0 deletions docs/pages/api-docs/data-grid/data-grid-pro.json
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@
"overlay",
"virtualScroller",
"virtualScrollerContent",
"virtualScrollerContent--overflowed",
"virtualScrollerRenderZone",
"pinnedColumns",
"pinnedColumns--left",
Expand All @@ -364,6 +365,7 @@
"root",
"row--editable",
"row--editing",
"row--lastVisible",
"row",
"rowCount",
"scrollArea",
Expand Down
2 changes: 2 additions & 0 deletions docs/pages/api-docs/data-grid/data-grid.json
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@
"overlay",
"virtualScroller",
"virtualScrollerContent",
"virtualScrollerContent--overflowed",
"virtualScrollerRenderZone",
"pinnedColumns",
"pinnedColumns--left",
Expand All @@ -311,6 +312,7 @@
"root",
"row--editable",
"row--editing",
"row--lastVisible",
"row",
"rowCount",
"scrollArea",
Expand Down
2 changes: 2 additions & 0 deletions docs/pages/x/api/data-grid/data-grid-pro.json
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@
"overlay",
"virtualScroller",
"virtualScrollerContent",
"virtualScrollerContent--overflowed",
"virtualScrollerRenderZone",
"pinnedColumns",
"pinnedColumns--left",
Expand All @@ -364,6 +365,7 @@
"root",
"row--editable",
"row--editing",
"row--lastVisible",
"row",
"rowCount",
"scrollArea",
Expand Down
2 changes: 2 additions & 0 deletions docs/pages/x/api/data-grid/data-grid.json
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@
"overlay",
"virtualScroller",
"virtualScrollerContent",
"virtualScrollerContent--overflowed",
"virtualScrollerRenderZone",
"pinnedColumns",
"pinnedColumns--left",
Expand All @@ -311,6 +312,7 @@
"root",
"row--editable",
"row--editing",
"row--lastVisible",
"row",
"rowCount",
"scrollArea",
Expand Down
9 changes: 9 additions & 0 deletions docs/translations/api-docs/data-grid/data-grid-pro-pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,11 @@
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the virtualization content"
},
"virtualScrollerContent--overflowed": {
"description": "Styles applied to {{nodeName}} when {{conditions}}.",
"nodeName": "the virtualization content",
"conditions": "its height is bigger than the virtualization container"
},
"virtualScrollerRenderZone": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the virtualization render zone"
Expand Down Expand Up @@ -445,6 +450,10 @@
"nodeName": "the row element",
"conditions": "the row is in edit mode"
},
"row--lastVisible": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the last visible row element on every page of the grid"
},
"row": { "description": "Styles applied to {{nodeName}}.", "nodeName": "the row element" },
"rowCount": {
"description": "Styles applied to {{nodeName}}.\nOnly works when pagination is disabled.",
Expand Down
9 changes: 9 additions & 0 deletions docs/translations/api-docs/data-grid/data-grid-pro-zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,11 @@
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the virtualization content"
},
"virtualScrollerContent--overflowed": {
"description": "Styles applied to {{nodeName}} when {{conditions}}.",
"nodeName": "the virtualization content",
"conditions": "its height is bigger than the virtualization container"
},
"virtualScrollerRenderZone": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the virtualization render zone"
Expand Down Expand Up @@ -445,6 +450,10 @@
"nodeName": "the row element",
"conditions": "the row is in edit mode"
},
"row--lastVisible": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the last visible row element on every page of the grid"
},
"row": { "description": "Styles applied to {{nodeName}}.", "nodeName": "the row element" },
"rowCount": {
"description": "Styles applied to {{nodeName}}.\nOnly works when pagination is disabled.",
Expand Down
9 changes: 9 additions & 0 deletions docs/translations/api-docs/data-grid/data-grid-pro.json
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,11 @@
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the virtualization content"
},
"virtualScrollerContent--overflowed": {
"description": "Styles applied to {{nodeName}} when {{conditions}}.",
"nodeName": "the virtualization content",
"conditions": "its height is bigger than the virtualization container"
},
"virtualScrollerRenderZone": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the virtualization render zone"
Expand Down Expand Up @@ -445,6 +450,10 @@
"nodeName": "the row element",
"conditions": "the row is in edit mode"
},
"row--lastVisible": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the last visible row element on every page of the grid"
},
"row": { "description": "Styles applied to {{nodeName}}.", "nodeName": "the row element" },
"rowCount": {
"description": "Styles applied to {{nodeName}}.\nOnly works when pagination is disabled.",
Expand Down
9 changes: 9 additions & 0 deletions docs/translations/api-docs/data-grid/data-grid-pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,11 @@
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the virtualization content"
},
"virtualScrollerContent--overflowed": {
"description": "Styles applied to {{nodeName}} when {{conditions}}.",
"nodeName": "the virtualization content",
"conditions": "its height is bigger than the virtualization container"
},
"virtualScrollerRenderZone": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the virtualization render zone"
Expand Down Expand Up @@ -414,6 +419,10 @@
"nodeName": "the row element",
"conditions": "the row is in edit mode"
},
"row--lastVisible": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the last visible row element on every page of the grid"
},
"row": { "description": "Styles applied to {{nodeName}}.", "nodeName": "the row element" },
"rowCount": {
"description": "Styles applied to {{nodeName}}.\nOnly works when pagination is disabled.",
Expand Down
9 changes: 9 additions & 0 deletions docs/translations/api-docs/data-grid/data-grid-zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,11 @@
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the virtualization content"
},
"virtualScrollerContent--overflowed": {
"description": "Styles applied to {{nodeName}} when {{conditions}}.",
"nodeName": "the virtualization content",
"conditions": "its height is bigger than the virtualization container"
},
"virtualScrollerRenderZone": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the virtualization render zone"
Expand Down Expand Up @@ -414,6 +419,10 @@
"nodeName": "the row element",
"conditions": "the row is in edit mode"
},
"row--lastVisible": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the last visible row element on every page of the grid"
},
"row": { "description": "Styles applied to {{nodeName}}.", "nodeName": "the row element" },
"rowCount": {
"description": "Styles applied to {{nodeName}}.\nOnly works when pagination is disabled.",
Expand Down
9 changes: 9 additions & 0 deletions docs/translations/api-docs/data-grid/data-grid.json
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,11 @@
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the virtualization content"
},
"virtualScrollerContent--overflowed": {
"description": "Styles applied to {{nodeName}} when {{conditions}}.",
"nodeName": "the virtualization content",
"conditions": "its height is bigger than the virtualization container"
},
"virtualScrollerRenderZone": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the virtualization render zone"
Expand Down Expand Up @@ -414,6 +419,10 @@
"nodeName": "the row element",
"conditions": "the row is in edit mode"
},
"row--lastVisible": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the last visible row element on every page of the grid"
},
"row": { "description": "Styles applied to {{nodeName}}.", "nodeName": "the row element" },
"rowCount": {
"description": "Styles applied to {{nodeName}}.\nOnly works when pagination is disabled.",
Expand Down
16 changes: 13 additions & 3 deletions packages/grid/x-data-grid/src/components/GridRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface GridRowProps {
cellFocus: GridCellIdentifier | null;
cellTabIndex: GridCellIdentifier | null;
editRowsState: GridEditRowsModel;
isLastVisible?: boolean;
onClick?: React.MouseEventHandler<HTMLDivElement>;
onDoubleClick?: React.MouseEventHandler<HTMLDivElement>;
onMouseEnter?: React.MouseEventHandler<HTMLDivElement>;
Expand All @@ -39,14 +40,20 @@ export interface GridRowProps {
type OwnerState = Pick<GridRowProps, 'selected'> & {
editable: boolean;
editing: boolean;
isLastVisible: boolean;
classes?: DataGridProcessedProps['classes'];
};

const useUtilityClasses = (ownerState: OwnerState) => {
const { editable, editing, selected, classes } = ownerState;

const { editable, editing, selected, isLastVisible, classes } = ownerState;
const slots = {
root: ['row', selected && 'selected', editable && 'row--editable', editing && 'row--editing'],
root: [
'row',
selected && 'selected',
editable && 'row--editable',
editing && 'row--editing',
isLastVisible && 'row--lastVisible',
],
};

return composeClasses(slots, getDataGridUtilityClass, classes);
Expand Down Expand Up @@ -79,6 +86,7 @@ function GridRow(props: React.HTMLAttributes<HTMLDivElement> & GridRowProps) {
cellFocus,
cellTabIndex,
editRowsState,
isLastVisible = false,
onClick,
onDoubleClick,
onMouseEnter,
Expand All @@ -96,6 +104,7 @@ function GridRow(props: React.HTMLAttributes<HTMLDivElement> & GridRowProps) {

const ownerState = {
selected,
isLastVisible,
classes: rootProps.classes,
editing: apiRef.current.getRowMode(rowId) === GridRowModes.Edit,
editable: rootProps.editMode === GridEditModes.Row,
Expand Down Expand Up @@ -261,6 +270,7 @@ GridRow.propTypes = {
editRowsState: PropTypes.object.isRequired,
firstColumnToRender: PropTypes.number.isRequired,
index: PropTypes.number.isRequired,
isLastVisible: PropTypes.bool,
lastColumnToRender: PropTypes.number.isRequired,
renderedColumns: PropTypes.arrayOf(PropTypes.object).isRequired,
row: PropTypes.object.isRequired,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import clsx from 'clsx';
import { unstable_composeClasses as composeClasses } from '@mui/material';
import { styled } from '@mui/material/styles';
import { styled, alpha, lighten, darken } from '@mui/material/styles';
import { getDataGridUtilityClass } from '../../constants/gridClasses';
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
import { DataGridProcessedProps } from '../../models/props/DataGridProps';
Expand All @@ -24,12 +24,20 @@ const GridFooterContainerRoot = styled('div', {
name: 'MuiDataGrid',
slot: 'FooterContainer',
overridesResolver: (props, styles) => styles.footerContainer,
})(() => ({
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
minHeight: 52, // Match TablePagination min height
}));
})(({ theme }) => {
const borderColor =
theme.palette.mode === 'light'
? lighten(alpha(theme.palette.divider, 1), 0.88)
: darken(alpha(theme.palette.divider, 1), 0.68);

return {
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
minHeight: 52, // Match TablePagination min height
borderTop: `1px solid ${borderColor}`,
};
});

export const GridFooterContainer = React.forwardRef<HTMLDivElement, GridFooterContainerProps>(
function GridFooterContainer(props: GridFooterContainerProps, ref) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@ export const GridRootStyles = styled('div', {
flexDirection: 'column',
[`&.${gridClasses.autoHeight}`]: {
height: 'auto',
[`& .${gridClasses['row--lastVisible']} .${gridClasses.cell}`]: {
borderColor: 'transparent',
},
},
[`& .${gridClasses['virtualScrollerContent--overflowed']} .${gridClasses['row--lastVisible']} .${gridClasses.cell}`]:
{
borderColor: 'transparent',
},
[`& .${gridClasses.columnHeader}, & .${gridClasses.cell}`]: {
WebkitTapHighlightColor: 'transparent',
lineHeight: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
import { getDataGridUtilityClass } from '../../constants/gridClasses';
import { DataGridProcessedProps } from '../../models/props/DataGridProps';

type OwnerState = { classes: DataGridProcessedProps['classes'] };
type OwnerState = { classes: DataGridProcessedProps['classes']; overflowedContent: boolean };

const useUtilityClasses = (ownerState: OwnerState) => {
const { classes } = ownerState;
const { classes, overflowedContent } = ownerState;

const slots = {
root: ['virtualScrollerContent'],
root: ['virtualScrollerContent', overflowedContent && 'virtualScrollerContent--overflowed'],
};

return composeClasses(slots, getDataGridUtilityClass, classes);
Expand All @@ -30,13 +30,21 @@ const GridVirtualScrollerContent = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(function GridVirtualScrollerContent(props, ref) {
const { className, ...other } = props;
const { className, style, ...other } = props;
const rootProps = useGridRootProps();
const ownerState = { classes: rootProps.classes };
const ownerState = {
classes: rootProps.classes,
overflowedContent: !rootProps.autoHeight && style?.minHeight === 'auto',
};
const classes = useUtilityClasses(ownerState);

return (
<VirtualScrollerContentRoot ref={ref} className={clsx(classes.root, className)} {...other} />
<VirtualScrollerContentRoot
ref={ref}
className={clsx(classes.root, className)}
style={style}
{...other}
/>
);
});

Expand Down
10 changes: 10 additions & 0 deletions packages/grid/x-data-grid/src/constants/gridClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ export interface GridClasses {
* Styles applied to the virtualization content.
*/
virtualScrollerContent: string;
/**
* Styles applied to the virtualization content when its height is bigger than the virtualization container.
*/
'virtualScrollerContent--overflowed': string;
/**
* Styles applied to the virtualization render zone.
*/
Expand Down Expand Up @@ -313,6 +317,10 @@ export interface GridClasses {
* Styles applied to the row element if the row is in edit mode.
*/
'row--editing': string;
/**
* Styles applied to the last visible row element on every page of the grid.
*/
'row--lastVisible': string;
/**
* Styles applied to the row element.
*/
Expand Down Expand Up @@ -442,6 +450,7 @@ export const gridClasses = generateUtilityClasses('MuiDataGrid', [
'row--editable',
'row--editing',
'row',
'row--lastVisible',
'rowCount',
'scrollArea--left',
'scrollArea--right',
Expand All @@ -452,6 +461,7 @@ export const gridClasses = generateUtilityClasses('MuiDataGrid', [
'toolbarFilterList',
'virtualScroller',
'virtualScrollerContent',
'virtualScrollerContent--overflowed',
'virtualScrollerRenderZone',
'pinnedColumns',
'pinnedColumns--left',
Expand Down
Loading