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] Improve column header separators #9183

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/pages/x/api/data-grid/data-grid-premium.json
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,6 @@
"columnHeaders",
"columnHeadersInner",
"columnHeadersInner--scrollable",
"columnSeparator--resizable",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or possibly keep this class until v7 for being non-breaking?

"columnSeparator--resizing",
"columnSeparator--sideLeft",
"columnSeparator--sideRight",
Expand Down
1 change: 0 additions & 1 deletion docs/pages/x/api/data-grid/data-grid-pro.json
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,6 @@
"columnHeaders",
"columnHeadersInner",
"columnHeadersInner--scrollable",
"columnSeparator--resizable",
"columnSeparator--resizing",
"columnSeparator--sideLeft",
"columnSeparator--sideRight",
Expand Down
1 change: 0 additions & 1 deletion docs/pages/x/api/data-grid/data-grid.json
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@
"columnHeaders",
"columnHeadersInner",
"columnHeadersInner--scrollable",
"columnSeparator--resizable",
"columnSeparator--resizing",
"columnSeparator--sideLeft",
"columnSeparator--sideRight",
Expand Down
5 changes: 0 additions & 5 deletions docs/translations/api-docs/data-grid/data-grid-premium.json
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,6 @@
"nodeName": "the column headers's inner element",
"conditions": "there is a horizontal scrollbar"
},
"columnSeparator--resizable": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the column header separator",
"conditions": "the column is resizable"
},
"columnSeparator--resizing": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the column header separator",
Expand Down
5 changes: 0 additions & 5 deletions docs/translations/api-docs/data-grid/data-grid-pro.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,6 @@
"nodeName": "the column headers's inner element",
"conditions": "there is a horizontal scrollbar"
},
"columnSeparator--resizable": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the column header separator",
"conditions": "the column is resizable"
},
"columnSeparator--resizing": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the column header separator",
Expand Down
5 changes: 0 additions & 5 deletions docs/translations/api-docs/data-grid/data-grid.json
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,6 @@
"nodeName": "the column headers's inner element",
"conditions": "there is a horizontal scrollbar"
},
"columnSeparator--resizable": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the column header separator",
"conditions": "the column is resizable"
},
"columnSeparator--resizing": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the column header separator",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export const useGridColumnResize = (
}

// Skip if the column isn't resizable
if (!event.currentTarget.classList.contains(gridClasses['columnSeparator--resizable'])) {
if (!event.currentTarget.classList.contains(gridClasses.columnSeparator)) {
return;
}

Expand Down Expand Up @@ -345,10 +345,7 @@ export const useGridColumnResize = (
});

const handleTouchStart = useEventCallback((event: any) => {
const cellSeparator = findParentElementFromClassName(
event.target,
gridClasses['columnSeparator--resizable'],
);
const cellSeparator = findParentElementFromClassName(event.target, gridClasses.columnSeparator);
// Let the event bubble if the target is not a col separator
if (!cellSeparator) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@ describe('<DataGridPro /> - Column Headers', () => {
clock.runToLast();
expect(screen.queryByRole('menu')).not.to.equal(null);

const separator = columnToResizeCell.querySelector(
`.${gridClasses['columnSeparator--resizable']}`,
)!;
const separator = columnToResizeCell.querySelector(`.${gridClasses.columnSeparator}`)!;
fireEvent.mouseDown(separator);
clock.runToLast();
expect(screen.queryByRole('menu')).to.equal(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ describe('<DataGridPro /> - Column pinning', () => {
)!;
expect(renderZone).toHaveInlineStyle({ transform: 'translate3d(100px, 0px, 0px)' });
const columnHeader = getColumnHeaderCell(0);
const separator = columnHeader.querySelector(`.${gridClasses['columnSeparator--resizable']}`)!;
const separator = columnHeader.querySelector(`.${gridClasses.columnSeparator}`)!;
fireEvent.mouseDown(separator, { clientX: 100 });
fireEvent.mouseMove(separator, { clientX: 110, buttons: 1 });
fireEvent.mouseUp(separator);
Expand All @@ -172,7 +172,7 @@ describe('<DataGridPro /> - Column pinning', () => {
)!;
expect(columnHeadersInner).toHaveInlineStyle({ transform: 'translate3d(100px, 0px, 0px)' });
const columnHeader = getColumnHeaderCell(0);
const separator = columnHeader.querySelector(`.${gridClasses['columnSeparator--resizable']}`)!;
const separator = columnHeader.querySelector(`.${gridClasses.columnSeparator}`)!;
fireEvent.mouseDown(separator, { clientX: 100 });
fireEvent.mouseMove(separator, { clientX: 110, buttons: 1 });
fireEvent.mouseUp(separator);
Expand Down Expand Up @@ -203,7 +203,7 @@ describe('<DataGridPro /> - Column pinning', () => {
const columnHeader = getColumnHeaderCell(2);
expect(columnHeader).toHaveInlineStyle({ width: '100px' });

const separator = columnHeader.querySelector(`.${gridClasses['columnSeparator--resizable']}`)!;
const separator = columnHeader.querySelector(`.${gridClasses.columnSeparator}`)!;
fireEvent.mouseDown(separator, { clientX: 200 });
fireEvent.mouseMove(separator, { clientX: 190, buttons: 1 });
fireEvent.mouseUp(separator);
Expand All @@ -221,7 +221,7 @@ describe('<DataGridPro /> - Column pinning', () => {
const columnHeader = getColumnHeaderCell(2);
expect(columnHeader).toHaveInlineStyle({ width: '100px' });

const separator = columnHeader.querySelector(`.${gridClasses['columnSeparator--resizable']}`)!;
const separator = columnHeader.querySelector(`.${gridClasses.columnSeparator}`)!;
fireEvent.mouseDown(separator, { clientX: 200 });
fireEvent.mouseMove(separator, { clientX: 210, buttons: 1 });
fireEvent.mouseUp(separator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ describe('<DataGridPro /> - Column Spanning', () => {
expect(getColumnHeaderCell(1).offsetWidth).to.equal(100);
expect(getCell(0, 0).offsetWidth).to.equal(200);

const separator = document.querySelector(`.${gridClasses['columnSeparator--resizable']}`)!;
const separator = document.querySelector(`.${gridClasses.columnSeparator}`)!;
fireEvent.mouseDown(separator, { clientX: 100 });
fireEvent.mouseMove(separator, { clientX: 200, buttons: 1 });
fireEvent.mouseUp(separator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('<DataGridPro /> - Columns', () => {

it('should allow to resize columns with the mouse', () => {
render(<Test columns={columns} />);
const separator = document.querySelector(`.${gridClasses['columnSeparator--resizable']}`)!;
const separator = document.querySelector(`.${gridClasses.columnSeparator}`)!;
fireEvent.mouseDown(separator, { clientX: 100 });
fireEvent.mouseMove(separator, { clientX: 110, buttons: 1 });
fireEvent.mouseUp(separator);
Expand All @@ -107,7 +107,7 @@ describe('<DataGridPro /> - Columns', () => {
this.skip();
}
render(<Test columns={columns} />);
const separator = document.querySelector(`.${gridClasses['columnSeparator--resizable']}`)!;
const separator = document.querySelector(`.${gridClasses.columnSeparator}`)!;
const now = Date.now();
fireEvent.touchStart(separator, {
changedTouches: [new Touch({ identifier: now, target: separator, clientX: 100 })],
Expand All @@ -125,7 +125,7 @@ describe('<DataGridPro /> - Columns', () => {
it('should call onColumnResize during resizing', () => {
const onColumnResize = spy();
render(<Test onColumnResize={onColumnResize} columns={columns} />);
const separator = document.querySelector(`.${gridClasses['columnSeparator--resizable']}`)!;
const separator = document.querySelector(`.${gridClasses.columnSeparator}`)!;
fireEvent.mouseDown(separator, { clientX: 100 });
fireEvent.mouseMove(separator, { clientX: 110, buttons: 1 });
fireEvent.mouseMove(separator, { clientX: 120, buttons: 1 });
Expand All @@ -138,7 +138,7 @@ describe('<DataGridPro /> - Columns', () => {
it('should call onColumnWidthChange after resizing', () => {
const onColumnWidthChange = spy();
render(<Test onColumnWidthChange={onColumnWidthChange} columns={columns} />);
const separator = document.querySelector(`.${gridClasses['columnSeparator--resizable']}`)!;
const separator = document.querySelector(`.${gridClasses.columnSeparator}`)!;
fireEvent.mouseDown(separator, { clientX: 100 });
fireEvent.mouseMove(separator, { clientX: 110, buttons: 1 });
fireEvent.mouseMove(separator, { clientX: 120, buttons: 1 });
Expand Down Expand Up @@ -185,9 +185,7 @@ describe('<DataGridPro /> - Columns', () => {
expect(getColumnHeaderCell(0)).toHaveInlineStyle({ width: '198px' });
expect(getColumnHeaderCell(1)).toHaveInlineStyle({ width: '100px' });

const separator = getColumnHeaderCell(1).querySelector(
`.${gridClasses['columnSeparator--resizable']}`,
)!;
const separator = getColumnHeaderCell(1).querySelector(`.${gridClasses.columnSeparator}`)!;

fireEvent.mouseDown(separator, { clientX: 100 });
fireEvent.mouseMove(separator, { clientX: 150, buttons: 1 });
Expand Down Expand Up @@ -242,9 +240,7 @@ describe('<DataGridPro /> - Columns', () => {
expect(getColumnHeaderCell(0)).toHaveInlineStyle({ width: '198px' });
expect(getColumnHeaderCell(1)).toHaveInlineStyle({ width: '100px' });

const separator = getColumnHeaderCell(1).querySelector(
`.${gridClasses['columnSeparator--resizable']}`,
)!;
const separator = getColumnHeaderCell(1).querySelector(`.${gridClasses.columnSeparator}`)!;

fireEvent.mouseDown(separator, { clientX: 100 });
fireEvent.mouseMove(separator, { clientX: 150, buttons: 1 });
Expand All @@ -265,9 +261,7 @@ describe('<DataGridPro /> - Columns', () => {
expect(getColumnHeaderCell(0)).toHaveInlineStyle({ width: '98px' });
expect(getColumnHeaderCell(1)).toHaveInlineStyle({ width: '200px' });

const separator = getColumnHeaderCell(1).querySelector(
`.${gridClasses['columnSeparator--resizable']}`,
)!;
const separator = getColumnHeaderCell(1).querySelector(`.${gridClasses.columnSeparator}`)!;

fireEvent.mouseDown(separator, { clientX: 100 });
fireEvent.mouseMove(separator, { clientX: 50, buttons: 1 });
Expand Down Expand Up @@ -305,9 +299,7 @@ describe('<DataGridPro /> - Columns', () => {
expect(getColumnHeaderCell(0)).toHaveInlineStyle({ width: '198px' });
expect(getColumnHeaderCell(1)).toHaveInlineStyle({ width: '100px' });

const separator = getColumnHeaderCell(1).querySelector(
`.${gridClasses['columnSeparator--resizable']}`,
)!;
const separator = getColumnHeaderCell(1).querySelector(`.${gridClasses.columnSeparator}`)!;

fireEvent.mouseDown(separator, { clientX: 100 });
fireEvent.mouseMove(separator, { clientX: 150, buttons: 1 });
Expand All @@ -327,9 +319,7 @@ describe('<DataGridPro /> - Columns', () => {

expect(getColumnHeaderCell(0)).toHaveInlineStyle({ width: '198px' });

const separator = getColumnHeaderCell(0).querySelector(
`.${gridClasses['columnSeparator--resizable']}`,
)!;
const separator = getColumnHeaderCell(0).querySelector(`.${gridClasses.columnSeparator}`)!;

fireEvent.mouseDown(separator, { clientX: 200 });
fireEvent.mouseMove(separator, { clientX: 100, buttons: 1 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe('<DataGridPro /> - Columns Visibility', () => {
fireEvent.click(document.querySelector('[role="tooltip"] [name="id"]')!);
expect(getColumnHeadersTextContent()).to.deep.equal(['id']);

const separator = document.querySelector(`.${gridClasses['columnSeparator--resizable']}`)!;
const separator = document.querySelector(`.${gridClasses.columnSeparator}`)!;
fireEvent.mouseDown(separator, { clientX: 100 });
fireEvent.mouseMove(separator, { clientX: 110, buttons: 1 });
fireEvent.mouseUp(separator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ enum GridColumnHeaderSeparatorSides {
}

export interface GridColumnHeaderSeparatorProps extends React.HTMLAttributes<HTMLDivElement> {
resizable: boolean;
resizing: boolean;
height: number;
side?: GridColumnHeaderSeparatorSides;
Expand All @@ -25,12 +24,11 @@ type OwnerState = GridColumnHeaderSeparatorProps & {
};

const useUtilityClasses = (ownerState: OwnerState) => {
const { resizable, resizing, classes, side } = ownerState;
const { resizing, classes, side } = ownerState;

const slots = {
root: [
'columnSeparator',
resizable && 'columnSeparator--resizable',
resizing && 'columnSeparator--resizing',
side && `columnSeparator--side${capitalize(side)}`,
],
Expand All @@ -41,13 +39,7 @@ const useUtilityClasses = (ownerState: OwnerState) => {
};

function GridColumnHeaderSeparatorRaw(props: GridColumnHeaderSeparatorProps) {
const {
resizable,
resizing,
height,
side = GridColumnHeaderSeparatorSides.Right,
...other
} = props;
const { resizing, height, side = GridColumnHeaderSeparatorSides.Right, ...other } = props;
const rootProps = useGridRootProps();
const ownerState = { ...props, side, classes: rootProps.classes };
const classes = useUtilityClasses(ownerState);
Expand Down Expand Up @@ -78,7 +70,6 @@ GridColumnHeaderSeparatorRaw.propTypes = {
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
height: PropTypes.number.isRequired,
resizable: PropTypes.bool.isRequired,
resizing: PropTypes.bool.isRequired,
side: PropTypes.oneOf(['left', 'right']),
} as any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const GridGenericColumnHeaderItem = React.forwardRef(function GridGenericColumnH
}
}, [apiRef, hasFocus]);

const showColumnHeaderSeparator = !rootProps.disableColumnResize && !!resizable;
return (
<div
ref={handleRef}
Expand Down Expand Up @@ -133,13 +134,14 @@ const GridGenericColumnHeaderItem = React.forwardRef(function GridGenericColumnH
</div>
{columnMenuIconButton}
</div>
<GridColumnHeaderSeparator
resizable={!rootProps.disableColumnResize && !!resizable}
resizing={isResizing}
height={height}
side={separatorSide}
{...columnHeaderSeparatorProps}
/>
{showColumnHeaderSeparator ? (
<GridColumnHeaderSeparator
resizing={isResizing}
height={height}
side={separatorSide}
{...columnHeaderSeparatorProps}
/>
) : null}
{columnMenu}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export const GridRootStyles = styled('div', {
{ [`& .${gridClasses.columnHeaderCheckbox}`]: styles.columnHeaderCheckbox },
{ [`& .${gridClasses.columnHeaderDraggableContainer}`]: styles.columnHeaderDraggableContainer },
{ [`& .${gridClasses.columnHeaderTitleContainer}`]: styles.columnHeaderTitleContainer },
{ [`& .${gridClasses['columnSeparator--resizable']}`]: styles['columnSeparator--resizable'] },
{ [`& .${gridClasses['columnSeparator--resizing']}`]: styles['columnSeparator--resizing'] },
{ [`& .${gridClasses.columnSeparator}`]: styles.columnSeparator },
{ [`& .${gridClasses.filterIcon}`]: styles.filterIcon },
Expand Down Expand Up @@ -162,6 +161,7 @@ export const GridRootStyles = styled('div', {
position: 'relative',
display: 'flex',
alignItems: 'center',
borderRight: '1px solid transparent',
},
[`& .${gridClasses['columnHeader--sorted']} .${gridClasses.iconButtonContainer}, & .${gridClasses['columnHeader--filtered']} .${gridClasses.iconButtonContainer}`]:
{
Expand Down Expand Up @@ -246,19 +246,6 @@ export const GridRootStyles = styled('div', {
flexDirection: 'column',
justifyContent: 'center',
color: borderColor,
},
[`& .${gridClasses.columnHeaders}:hover .${gridClasses.columnSeparator}, .${gridClasses['columnSeparator--resizing']}`]:
{
visibility: 'visible',
width: 'auto',
},
[`& .${gridClasses['columnSeparator--sideLeft']}`]: {
left: -12,
},
[`& .${gridClasses['columnSeparator--sideRight']}`]: {
right: -12,
},
[`& .${gridClasses['columnSeparator--resizable']}`]: {
cursor: 'col-resize',
touchAction: 'none',
'&:hover': {
Expand All @@ -275,6 +262,21 @@ export const GridRootStyles = styled('div', {
pointerEvents: 'none',
},
},
[`& .${gridClasses.columnHeaders}:hover`]: {
[`& .${gridClasses.columnSeparator}, .${gridClasses['columnSeparator--resizing']}`]: {
visibility: 'visible',
width: 'auto',
},
[`& .${gridClasses.columnHeader}`]: {
borderRightColor: `${borderColor}`,
},
},
[`& .${gridClasses['columnSeparator--sideLeft']}`]: {
left: -12,
},
[`& .${gridClasses['columnSeparator--sideRight']}`]: {
right: -12,
},
[`& .${gridClasses.iconSeparator}`]: {
color: 'inherit',
},
Expand Down Expand Up @@ -422,14 +424,17 @@ export const GridRootStyles = styled('div', {
},
[`.${gridClasses.withBorderColor}`]: {
borderColor,
borderRightColor: 'transparent',
},
[`& .${gridClasses['cell--withRightBorder']}`]: {
borderRightWidth: '1px',
borderRightStyle: 'solid',
borderRightColor: borderColor,
},
[`& .${gridClasses['columnHeader--withRightBorder']}`]: {
borderRightWidth: '1px',
borderRightStyle: 'solid',
borderRightColor: borderColor,
},
[`& .${gridClasses['cell--textLeft']}`]: {
justifyContent: 'flex-start',
Expand Down
Loading