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

[DataGridPro] Fix missing border in right-pinned columns #4197

Merged

Conversation

cherniavskii
Copy link
Member

@cherniavskii cherniavskii commented Mar 15, 2022

Fixes #4194

Codesandbox: https://codesandbox.io/s/datagridpro-v5-quick-start-forked-qx8vfl

Changelog

  • The showCellRightBorder was renamed to showCellVerticalBorder
  • The showColumnRightBorder was renamed to showColumnVerticalBorder
  • The .MuiDataGrid-withBorder CSS class was renamed to .MuiDataGrid-withBorderColor and it only sets border-color CSS property now.

@mui-bot
Copy link

mui-bot commented Mar 15, 2022

Messages
📖 Netlify deploy preview: https://deploy-preview-4197--material-ui-x.netlify.app/

These are the results for the performance tests:

Test case Unit Min Max Median Mean σ
Filter 100k rows ms 655.1 1,554.8 655.1 981.76 327.233
Sort 100k rows ms 619.4 1,371.5 1,203.6 1,095.38 254.05
Select 100k rows ms 219.1 335 302.4 278.66 46.53
Deselect 100k rows ms 200.1 374.6 254.4 263.2 62.365

Generated by 🚫 dangerJS against 09856d8

@cherniavskii cherniavskii requested a review from m4theushw March 15, 2022 12:11
@cherniavskii cherniavskii added bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! feature: Rendering layout Related to the data grid Rendering engine labels Mar 15, 2022
@@ -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)}`,
Copy link
Member

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.

Copy link
Member Author

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:

Maybe we should add separate borderColor class and apply it everywhere border is used?

Copy link
Member

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.

Copy link
Member Author

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 applies border-color only
  • withRightBorder that applies border-right-width and border-right-style only

I've also used withBorder to apply border color to right-pinned container.

Copy link
Member

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.

Copy link
Member Author

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:

  1. I don't see a way to set showLeftBorder={true} only for first cells in the right-pinned section.

  2. Applying left border to cell instead of right pinned columns container results in double border:

    borderLeft on right-pinned columns container
    Screenshot 2022-04-04 at 19 54 15
    borderLeft on cell
    Screenshot 2022-04-04 at 19 52 52
    I didn't find a way to avoid this double border.

Copy link
Member Author

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

@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Mar 18, 2022
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Mar 22, 2022
@cherniavskii cherniavskii requested a review from m4theushw March 22, 2022 18:47
Copy link
Member

@m4theushw m4theushw left a 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.

image

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.

Maybe getRowProps needs to know which side the row will be rendered, we only know the ID.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Mar 28, 2022
@github-actions

This comment was marked as outdated.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 4, 2022
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 9, 2022
@github-actions

This comment was marked as outdated.

@cherniavskii cherniavskii mentioned this pull request Apr 27, 2022
41 tasks
@DanailH DanailH changed the base branch from master to next September 12, 2022 13:09
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Dec 5, 2022
@cherniavskii cherniavskii force-pushed the showCellRightBorder-right-pinned-columns branch 3 times, most recently from dfdbcf2 to df1c064 Compare December 6, 2022 12:12
@cherniavskii cherniavskii force-pushed the showCellRightBorder-right-pinned-columns branch from df1c064 to 96a23a7 Compare December 6, 2022 13:20
packages/grid/x-data-grid/src/components/cell/GridCell.tsx Outdated Show resolved Hide resolved
Comment on lines +361 to +363
[`.${gridClasses.withBorderColor}`]: {
borderColor,
},
Copy link
Member

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?

Suggested change
[`.${gridClasses.withBorderColor}`]: {
borderColor,
},
[`&.${gridClasses.withBorderColor}`]: {
borderColor,
},
[`.${gridClasses.withBorderColor}`]: {
borderColor,
},

Copy link
Member Author

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.

@cherniavskii cherniavskii changed the title [DataGridPro] Fix missing border in right-pinned columns with showCellRightBorder [DataGridPro] Fix missing border in right-pinned columns Dec 13, 2022
@cherniavskii cherniavskii merged commit 1ec26eb into mui:next Dec 13, 2022
@cherniavskii cherniavskii deleted the showCellRightBorder-right-pinned-columns branch December 13, 2022 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! feature: Rendering layout Related to the data grid Rendering engine
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DataGridPro] Column pining issue with showCellRightBorder
3 participants