-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[DataGridPro] Fix missing border in right-pinned columns #4197
[DataGridPro] Fix missing border in right-pinned columns #4197
Conversation
These are the results for the performance tests:
|
@@ -136,6 +138,10 @@ const VirtualScrollerPinnedColumns = styled('div', { | |||
}), | |||
...(ownerState.side === GridPinnedPosition.left && { left: 0, float: 'left' }), | |||
...(ownerState.side === GridPinnedPosition.right && { right: 0, float: 'right' }), | |||
...(ownerState.side === GridPinnedPosition.right && | |||
ownerState.showCellRightBorder && { | |||
borderLeft: `1px solid ${getBorderColor(theme)}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this is the right approach. Currently, if showCellRightBorder
is on the cells receive the .MuiDataGrid-withBorder
class. This class is specifically to change the border of the cells. Here we're changing the meaning of showCellRightBorder
by applying a border not to the pinned cells but to their container. If the user wants to change the color of the cell border he will have to change in two places: here and in .MuiDataGrid-withBorder
.
My proposal is to change .MuiDataGrid-withBorder
to only set the border color, then the cells will set the border width/style on the appropriate side.
For v6 I agree to rename this prop to showCellVerticalBorder
or other name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point!
If the user wants to change the color of the cell border he will have to change in two places: here and in .MuiDataGrid-withBorder.
But there's more places with border color anyway:
border: `1px solid ${borderColor}`, color: borderColor, borderBottom: `1px solid ${borderColor}`,
Maybe we should add separate borderColor
class and apply it everywhere border is used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah but these other borders affect other parts, not the cells. Currently, .MuiDataGrid-withBorder
only impacts the cell border.
Maybe we should add separate borderColor class and apply it everywhere border is used?
We'll have two classes for borders. In v6 I think we can unify this behavior and apply MuiDataGrid-withBorder
to the grid instead, not the cells. Then, we can have a single border color. It could also be a CSS variable, to be used in color
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I've split withBorder
styles into two classes:
withBorder
that appliesborder-color
onlywithRightBorder
that appliesborder-right-width
andborder-right-style
only
I've also used withBorder
to apply border color to right-pinned container.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We miss a withLeftBorder
applying border-left-width
and border-right-style
to the cell, not to the right pinned columns container.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are 2 problems with that:
-
I don't see a way to set
showLeftBorder={true}
only for first cells in the right-pinned section. -
Applying left border to cell instead of right pinned columns container results in double border:
borderLeft on right-pinned columns container
borderLeft on cell
I didn't find a way to avoid this double border.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've renamed showCellRightBorder
to showCellVerticalBorder
, showColumnRightBorder
to showColumnVerticalBorder
and added withBorderColor
CSS class that sets the border color for both cells and column headers
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're almost there.
If I change the color of MuiDataGrid-withBorder
it doesn't apply to the bottom border of the cells in the right pinned columns.
I think the cells should have a showLeftBorder
prop. If either showRightBorder
or showLeftBorder
is enabled, we add MuiDataGrid-withBorder
and the respective border class. To set this prop to true is tricky. One way is to reuse getRowProps
and pass this prop to GridRow
and GridRow
pass it only to the first cell.
mui-x/packages/grid/x-data-grid-pro/src/components/DataGridProVirtualScroller.tsx
Line 174 in 3ba334d
const getRowProps = (id: GridRowId) => { |
Maybe getRowProps
needs to know which side the row will be rendered, we only know the ID.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
dfdbcf2
to
df1c064
Compare
df1c064
to
96a23a7
Compare
[`.${gridClasses.withBorderColor}`]: { | ||
borderColor, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered removing the borderColor
above and also use the border class here?
[`.${gridClasses.withBorderColor}`]: { | |
borderColor, | |
}, | |
[`&.${gridClasses.withBorderColor}`]: { | |
borderColor, | |
}, | |
[`.${gridClasses.withBorderColor}`]: { | |
borderColor, | |
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I did consider it, but it breaks this demo: https://mui.com/x/react-data-grid/style/#using-the-sx-prop
This means that you won't be able to override the border of the grid with:
<DataGrid
sx={{ borderColor: 'primary.light' }}
/>
Because the default border color has higher specificity:
[`&.${gridClasses.withBorderColor}`]: {
borderColor,
},
So I decided to not to do this and allow to override grid external border color with sx
instead.
showCellRightBorder
Fixes #4194
Codesandbox: https://codesandbox.io/s/datagridpro-v5-quick-start-forked-qx8vfl
Changelog
showCellRightBorder
was renamed toshowCellVerticalBorder
showColumnRightBorder
was renamed toshowColumnVerticalBorder
.MuiDataGrid-withBorder
CSS class was renamed to.MuiDataGrid-withBorderColor
and it only setsborder-color
CSS property now.