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] Column header design updates #14293

Merged
merged 18 commits into from
Sep 3, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -617,10 +617,10 @@
"description": "Set the area in <code>px</code> at the bottom of the grid viewport where onRowsScrollEnd is called."
},
"showCellVerticalBorder": {
"description": "If <code>true</code>, the vertical borders of the cells are displayed."
"description": "If <code>true</code>, vertical borders will be displayed between cells."
},
"showColumnVerticalBorder": {
"description": "If <code>true</code>, the right border of the column headers are displayed."
"description": "If <code>true</code>, vertical borders will be displayed between column header items."
},
"slotProps": {
"description": "Overridable components props dynamically passed to the component at rendering."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,10 +559,10 @@
"description": "Set the area in <code>px</code> at the bottom of the grid viewport where onRowsScrollEnd is called."
},
"showCellVerticalBorder": {
"description": "If <code>true</code>, the vertical borders of the cells are displayed."
"description": "If <code>true</code>, vertical borders will be displayed between cells."
},
"showColumnVerticalBorder": {
"description": "If <code>true</code>, the right border of the column headers are displayed."
"description": "If <code>true</code>, vertical borders will be displayed between column header items."
},
"slotProps": {
"description": "Overridable components props dynamically passed to the component at rendering."
Expand Down
4 changes: 2 additions & 2 deletions docs/translations/api-docs/data-grid/data-grid/data-grid.json
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,10 @@
"description": "Override the height/width of the Data Grid inner scrollbar."
},
"showCellVerticalBorder": {
"description": "If <code>true</code>, the vertical borders of the cells are displayed."
"description": "If <code>true</code>, vertical borders will be displayed between cells."
},
"showColumnVerticalBorder": {
"description": "If <code>true</code>, the right border of the column headers are displayed."
"description": "If <code>true</code>, vertical borders will be displayed between column header items."
},
"slotProps": {
"description": "Overridable components props dynamically passed to the component at rendering."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -989,12 +989,12 @@ DataGridPremiumRaw.propTypes = {
*/
scrollEndThreshold: PropTypes.number,
/**
* If `true`, the vertical borders of the cells are displayed.
* If `true`, vertical borders will be displayed between cells.
* @default false
*/
showCellVerticalBorder: PropTypes.bool,
/**
* If `true`, the right border of the column headers are displayed.
* If `true`, vertical borders will be displayed between column header items.
* @default false
*/
showColumnVerticalBorder: PropTypes.bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,9 @@ const GridAggregationFunctionLabel = styled('div', {
})<{ ownerState: OwnerState }>(({ theme }) => {
return {
fontSize: theme.typography.caption.fontSize,
lineHeight: theme.typography.caption.fontSize,
position: 'absolute',
bottom: 4,
fontWeight: theme.typography.fontWeightMedium,
color: (theme.vars || theme).palette.primary.dark,
textTransform: 'uppercase',
lineHeight: 'normal',
Copy link
Member

@MBilalShafi MBilalShafi Aug 28, 2024

Choose a reason for hiding this comment

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

I'm wondering if there is a possibility some users customizing it using theme.*.* variables. What do you think? 🤔

Copy link
Contributor Author

@KenanYusuf KenanYusuf Aug 28, 2024

Choose a reason for hiding this comment

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

I'm purposefully deviating from the theme.typography.caption.lineHeight value here because it is too large. normal line-height should keep the spacing looking ok between the column header title and aggregation label I think.

If users want to override it, they have the class I guess?

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, but I'm only worried if some existing users' styles would break with this.
It's obviously not very likely but theoretically, some users may be using theme.typography.caption.lineHeight to override this style.

It's a nitpick though. Feel free to merge it in current shape.

color: theme.palette.text.secondary,
marginTop: -1,
};
});

Expand Down
4 changes: 2 additions & 2 deletions packages/x-data-grid-pro/src/DataGridPro/DataGridPro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -895,12 +895,12 @@ DataGridProRaw.propTypes = {
*/
scrollEndThreshold: PropTypes.number,
/**
* If `true`, the vertical borders of the cells are displayed.
* If `true`, vertical borders will be displayed between cells.
* @default false
*/
showCellVerticalBorder: PropTypes.bool,
/**
* If `true`, the right border of the column headers are displayed.
* If `true`, vertical borders will be displayed between column header items.
* @default false
*/
showColumnVerticalBorder: PropTypes.bool,
Expand Down
16 changes: 8 additions & 8 deletions packages/x-data-grid-pro/src/tests/columns.DataGridPro.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ describe('<DataGridPro /> - Columns', () => {
await microtasks();
expect(onColumnWidthChange.callCount).to.be.at.least(2);
const widthArgs = onColumnWidthChange.args.map((arg) => arg[0].width);
const isWidth116Present = widthArgs.some((width) => width === 116);
expect(isWidth116Present).to.equal(true);
const isWidth114Present = widthArgs.some((width) => width === 114);
expect(isWidth114Present).to.equal(true);
const colDefWidthArgs = onColumnWidthChange.args.map((arg) => arg[0].colDef.width);
const isColDefWidth116Present = colDefWidthArgs.some((width) => width === 116);
expect(isColDefWidth116Present).to.equal(true);
const isColDefWidth114Present = colDefWidthArgs.some((width) => width === 114);
expect(isColDefWidth114Present).to.equal(true);
});

it('should not affect other cell elements that are not part of the main DataGrid instance', () => {
Expand Down Expand Up @@ -473,7 +473,7 @@ describe('<DataGridPro /> - Columns', () => {
render(<Test rows={rows} columns={columns} />);
await apiRef.current.autosizeColumns();
await microtasks();
expect(getWidths()).to.deep.equal([213, 235]);
expect(getWidths()).to.deep.equal([211, 233]);
});

it('should work through double-clicking the separator', async () => {
Expand All @@ -483,14 +483,14 @@ describe('<DataGridPro /> - Columns', () => {
)[1];
fireEvent.doubleClick(separator);
await microtasks();
expect(getWidths()).to.deep.equal([100, 235]);
expect(getWidths()).to.deep.equal([100, 233]);
});

it('should work on mount', async () => {
render(<Test rows={rows} columns={columns} autosizeOnMount />);
await microtasks(); /* first effect after render */
await microtasks(); /* async autosize operation */
expect(getWidths()).to.deep.equal([213, 235]);
expect(getWidths()).to.deep.equal([211, 233]);
});

describe('options', () => {
Expand All @@ -506,7 +506,7 @@ describe('<DataGridPro /> - Columns', () => {
});

it('.includeHeaders works', async () => {
await autosize({ includeHeaders: true }, [213, 235]);
await autosize({ includeHeaders: true }, [211, 233]);
});

it('.includeOutliers works', async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/x-data-grid/src/DataGrid/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -744,12 +744,12 @@ DataGridRaw.propTypes = {
*/
scrollbarSize: PropTypes.number,
/**
* If `true`, the vertical borders of the cells are displayed.
* If `true`, vertical borders will be displayed between cells.
* @default false
*/
showCellVerticalBorder: PropTypes.bool,
/**
* If `true`, the right border of the column headers are displayed.
* If `true`, vertical borders will be displayed between column header items.
* @default false
*/
showColumnVerticalBorder: PropTypes.bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const ColumnHeaderMenuIcon = React.memo((props: ColumnHeaderMenuIconProps
id={columnMenuButtonId}
{...rootProps.slotProps?.baseIconButton}
>
<rootProps.slots.columnMenuIcon fontSize="small" />
<rootProps.slots.columnMenuIcon fontSize="inherit" />
</rootProps.slots.baseIconButton>
</rootProps.slots.baseTooltip>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function GridColumnGroupHeader(props: GridColumnGroupHeaderProps) {
pinnedPosition,
indexInSection,
sectionLength,
rootProps.showCellVerticalBorder,
rootProps.showColumnVerticalBorder,
gridHasFiller,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function GridColumnHeaderItem(props: GridColumnHeaderItemProps) {
pinnedPosition,
indexInSection,
sectionLength,
rootProps.showCellVerticalBorder,
rootProps.showColumnVerticalBorder,
gridHasFiller,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,7 @@ function GridColumnHeaderSeparatorRaw(props: GridColumnHeaderSeparatorProps) {

return (
// 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 ? 0 : 1 }}
{...other}
onClick={stopClick}
>
<div className={classes.root} style={{ minHeight: height }} {...other} onClick={stopClick}>
<rootProps.slots.columnResizeIcon className={classes.icon} />
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const GridColumnHeaderTitleRoot = styled('div', {
overflow: 'hidden',
whiteSpace: 'nowrap',
fontWeight: 'var(--unstable_DataGrid-headWeight)',
lineHeight: 'normal',
});

const ColumnHeaderInnerTitle = React.forwardRef<
Expand Down
Loading