Skip to content

Commit

Permalink
[DataGrid] Fix column separators (#12808)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrew Cherniavskyi <andrew@mui.com>
  • Loading branch information
romgrk and cherniavskii committed Apr 17, 2024
1 parent 23f912d commit f047a84
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 6 deletions.
6 changes: 6 additions & 0 deletions docs/pages/x/api/data-grid/data-grid-premium.json
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,12 @@
"description": "Styles applied to the column header if the column has a filter applied to it.",
"isGlobal": false
},
{
"key": "columnHeader--last",
"className": "MuiDataGridPremium-columnHeader--last",
"description": "Styles applied to the last column header element.",
"isGlobal": false
},
{
"key": "columnHeader--moving",
"className": "MuiDataGridPremium-columnHeader--moving",
Expand Down
6 changes: 6 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 @@ -1186,6 +1186,12 @@
"description": "Styles applied to the column header if the column has a filter applied to it.",
"isGlobal": false
},
{
"key": "columnHeader--last",
"className": "MuiDataGridPro-columnHeader--last",
"description": "Styles applied to the last column header element.",
"isGlobal": false
},
{
"key": "columnHeader--moving",
"className": "MuiDataGridPro-columnHeader--moving",
Expand Down
6 changes: 6 additions & 0 deletions docs/pages/x/api/data-grid/data-grid.json
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,12 @@
"description": "Styles applied to the column header if the column has a filter applied to it.",
"isGlobal": false
},
{
"key": "columnHeader--last",
"className": "MuiDataGrid-columnHeader--last",
"description": "Styles applied to the last column header element.",
"isGlobal": false
},
{
"key": "columnHeader--moving",
"className": "MuiDataGrid-columnHeader--moving",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,10 @@
"nodeName": "the column header",
"conditions": "the column has a filter applied to it"
},
"columnHeader--last": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the last column header element"
},
"columnHeader--moving": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the column header",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,10 @@
"nodeName": "the column header",
"conditions": "the column has a filter applied to it"
},
"columnHeader--last": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the last column header element"
},
"columnHeader--moving": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the column header",
Expand Down
4 changes: 4 additions & 0 deletions docs/translations/api-docs/data-grid/data-grid/data-grid.json
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,10 @@
"nodeName": "the column header",
"conditions": "the column has a filter applied to it"
},
"columnHeader--last": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the last column header element"
},
"columnHeader--moving": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the column header",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { unstable_composeClasses as composeClasses, unstable_useId as useId } from '@mui/utils';
import { fastMemo } from '../../utils/fastMemo';
import { GridStateColDef } from '../../models/colDef/gridColDef';
Expand All @@ -9,7 +10,7 @@ import { GridColumnHeaderSortIcon } from './GridColumnHeaderSortIcon';
import { GridColumnHeaderSeparatorProps } from './GridColumnHeaderSeparator';
import { ColumnHeaderMenuIcon } from './ColumnHeaderMenuIcon';
import { GridColumnHeaderMenu } from '../menu/columnMenu/GridColumnHeaderMenu';
import { getDataGridUtilityClass } from '../../constants/gridClasses';
import { gridClasses, getDataGridUtilityClass } from '../../constants/gridClasses';
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
import { DataGridProcessedProps } from '../../models/props/DataGridProps';
import { GridGenericColumnHeaderItem } from './GridGenericColumnHeaderItem';
Expand All @@ -25,6 +26,7 @@ interface GridColumnHeaderItemProps {
headerHeight: number;
isDragging: boolean;
isResizing: boolean;
isLast: boolean;
sortDirection: GridSortDirection;
sortIndex?: number;
filterItemsCounter?: number;
Expand Down Expand Up @@ -94,6 +96,7 @@ function GridColumnHeaderItem(props: GridColumnHeaderItemProps) {
colIndex,
headerHeight,
isResizing,
isLast,
sortDirection,
sortIndex,
filterItemsCounter,
Expand Down Expand Up @@ -293,7 +296,7 @@ function GridColumnHeaderItem(props: GridColumnHeaderItemProps) {
width={colDef.computedWidth}
columnMenuIconButton={columnMenuIconButton}
columnTitleIconButtons={columnTitleIconButtons}
headerClassName={headerClassName}
headerClassName={clsx(headerClassName, isLast && gridClasses['columnHeader--last'])}
label={label}
resizable={!rootProps.disableColumnResize && !!colDef.resizable}
data-field={colDef.field}
Expand Down Expand Up @@ -321,6 +324,7 @@ GridColumnHeaderItem.propTypes = {
headerHeight: PropTypes.number.isRequired,
indexInSection: PropTypes.number.isRequired,
isDragging: PropTypes.bool.isRequired,
isLast: PropTypes.bool.isRequired,
isResizing: PropTypes.bool.isRequired,
pinnedPosition: PropTypes.oneOf(['left', 'right']),
sectionLength: PropTypes.number.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function GridColumnHeaderSeparatorRaw(props: GridColumnHeaderSeparatorProps) {
// eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions
<div
className={classes.root}
style={{ minHeight: height, opacity: rootProps.showColumnVerticalBorder ? 1 : 0 }}
style={{ minHeight: height, opacity: rootProps.showColumnVerticalBorder ? 0 : 1 }}
{...other}
onClick={stopClick}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ export const GridRootStyles = styled('div', {
position: 'relative',
display: 'flex',
alignItems: 'center',
},
[`& .${c['columnHeader--last']}`]: {
overflow: 'hidden',
},
[`& .${c['columnHeader--sorted']} .${c.iconButtonContainer}, & .${c['columnHeader--filtered']} .${c.iconButtonContainer}`]:
Expand Down
11 changes: 8 additions & 3 deletions packages/x-data-grid/src/constants/gridClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ export interface GridClasses {
* Styles applied to the selection checkbox element.
*/
checkboxInput: string;
/**
* Styles applied to the column header element.
*/
columnHeader: string;
/**
* Styles applied to the column header if `headerAlign="center"`.
*/
Expand Down Expand Up @@ -156,9 +160,9 @@ export interface GridClasses {
'columnHeader--pinnedLeft': string;
'columnHeader--pinnedRight': string;
/**
* Styles applied to the column header element.
* Styles applied to the last column header element.
*/
columnHeader: string;
'columnHeader--last': string;
/**
* Styles applied to the header checkbox cell element.
*/
Expand Down Expand Up @@ -635,6 +639,7 @@ export const gridClasses = generateUtilityClasses<GridClassKey>('MuiDataGrid', [
'cellSkeleton',
'cellOffsetLeft',
'checkboxInput',
'columnHeader',
'columnHeader--alignCenter',
'columnHeader--alignLeft',
'columnHeader--alignRight',
Expand All @@ -646,7 +651,7 @@ export const gridClasses = generateUtilityClasses<GridClassKey>('MuiDataGrid', [
'columnHeader--filtered',
'columnHeader--pinnedLeft',
'columnHeader--pinnedRight',
'columnHeader',
'columnHeader--last',
'columnHeaderCheckbox',
'columnHeaderDraggableContainer',
'columnHeaderTitle',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ export const useGridColumnHeaders = (props: UseGridColumnHeadersProps) => {
colDef={colDef}
colIndex={columnIndex}
isResizing={resizeCol === colDef.field}
isLast={columnIndex === columnPositions.length - 1}
hasFocus={hasFocus}
tabIndex={tabIndex}
pinnedPosition={pinnedPosition}
Expand Down

0 comments on commit f047a84

Please sign in to comment.