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] Add default background color to grid #16066

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

KenanYusuf
Copy link
Member

@KenanYusuf KenanYusuf commented Jan 3, 2025

Closes #15517

Changelog

Breaking changes

  • The Data Grid now has a default background color, and its customization has moved from theme.mixins.MuiDataGrid to theme.palette.DataGrid with the following properties:

    • bg: Sets the entire grid's background color (new property)
    • headerBg: Sets the header background color (previously named containerBackground)
    • pinnedBg: Sets pinned rows and columns background color (previously named pinnedBackground)
     const theme = createTheme({
    -  mixins: {
    -    MuiDataGrid: {
    -      containerBackground: '#f8fafc',
    -      pinnedBackground: '#f1f5f9',
    -    },
    -  },
    +  palette: {
    +    DataGrid: {
    +      bg: '#f8fafc',
    +      headerBg: '#e2e8f0',
    +      pinnedBg: '#f1f5f9',
    +    },
    +  },
     });

@KenanYusuf KenanYusuf marked this pull request as draft January 3, 2025 11:44
@KenanYusuf KenanYusuf added breaking change component: data grid This is the name of the generic UI component, not the React module! v8.x design This is about UI or UX design, please involve a designer customization: theme Centered around the theming features labels Jan 3, 2025
@mui-bot
Copy link

mui-bot commented Jan 3, 2025

const pinnedBackground = t.mixins.MuiDataGrid?.pinnedBackground ?? containerBackground;
: (t.mixins.MuiDataGrid?.background ?? t.palette.background.default);
const headerBackground = t.mixins.MuiDataGrid?.headerBackground ?? background;
const pinnedBackground = t.mixins.MuiDataGrid?.pinnedBackground ?? background;
Copy link
Member Author

@KenanYusuf KenanYusuf Jan 3, 2025

Choose a reason for hiding this comment

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

Currently, containerBackground is applied to column headers and pinned rows. IMO, it makes more sense to use the pinnedBackground color for pinned rows. With this change, containerBackground would only change the color of column headers, hence why I have renamed it to headerBackground.

It would be a second breaking change in addition to adding a background color to the grid.

Any concerns with this change? @mui/xgrid

@@ -663,7 +664,7 @@ export const GridRootStyles = styled('div', {
backgroundColor: pinnedSelectedBackgroundColor,
},
},
[`& .${c.virtualScrollerContent} .${c.row}`]: {
Copy link
Member Author

@KenanYusuf KenanYusuf Jan 3, 2025

Choose a reason for hiding this comment

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

Ensures that pinned column cells in pinned rows get hover styles too.

Before - Hovering pinned row

Screenshot 2025-01-03 at 11 56 50

After - Hovering pinned row

Screenshot 2025-01-03 at 11 57 01

// Headers, and top & bottom fixed rows
containerBackground: '#343434',
// Container background
background: '#fafaf9',
Copy link
Member

Choose a reason for hiding this comment

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

How to handle dark mode here? It would be great to have this included in this demo.

Copy link
Member Author

@KenanYusuf KenanYusuf Jan 24, 2025

Choose a reason for hiding this comment

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

Mentioned here #16066 (comment) and updated the docs

Comment on lines 149 to 151
const background = t.vars
? t.vars.palette.background.default
: (t.mixins.MuiDataGrid?.containerBackground ?? t.palette.background.default);
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't t.mixins.MuiDataGrid?.containerBackground be used if provided, regardless of t.vars?

const background =
  t.mixins.MuiDataGrid?.containerBackground ??
  (t.vars ? t.vars.palette.background.default : t.palette.background.default);

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, the priority was wrong, good spot. Fixed e2e9b02

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 10, 2025
Copy link

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

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 15, 2025
// Pinned rows and columns background
pinnedBg: '#f1f5f9',
// Column header background
headerBg: '#eaeff5',
Copy link
Member Author

@KenanYusuf KenanYusuf Jan 24, 2025

Choose a reason for hiding this comment

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

This is another breaking change to make Data Grid theming consistent with Material UI.

Instead of using the mixins theme property, we add DataGrid to the palette—in addition to being consistent with other component color options, this gives us built-in support for light/dark mode theming with colorSchemes (as shown in the snippet below this).

Material use bg instead of background, so also updated the property names for consistency.

@KenanYusuf KenanYusuf changed the title [DataGrid] Add background-color to grid [DataGrid] Add default background color to grid Jan 24, 2025
@KenanYusuf KenanYusuf marked this pull request as ready for review January 24, 2025 10:24
@KenanYusuf KenanYusuf requested a review from a team January 24, 2025 11:13
### CSS classes and styling
- `bg`: Sets the entire grid's background color (new property)
- `headerBg`: Sets the header background color (previously named `containerBackground`)
- `pinnedBg`: Sets pinned rows and columns background color (previously named `pinnedBackground`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- `pinnedBg`: Sets pinned rows and columns background color (previously named `pinnedBackground`)
- `pinnedBg`: Sets the background color of pinned rows and columns (previously named `pinnedBackground`)

@@ -116,26 +116,64 @@ The following demo illustrates how this can be achieved.

{{"demo": "StripedGrid.js", "bg": "inline"}}

## Theme header and pinned sections
## Theme container, header and pinned sections
Copy link
Contributor

Choose a reason for hiding this comment

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

Oxford comma. 😁 and is "Theme" necessary here? If not I think it's better without, for the sake of keeping the header as short as possible. I'm on the fence about whether or not to pluralize everything so I'll leave that to your judgement.

Suggested change
## Theme container, header and pinned sections
## Containers, headers, and pinned sections

By default, the Data Grid uses the Material UI `theme.palette.background.default` color for the background of its header and pinned sections. These elements require a solid color to hide the scrollable content behind them. You can override that color with the following configuration:
By default, the Data Grid uses the Material UI `theme.palette.background.default` color for the background color of the grid container, the column headers, and the pinned rows and columns.

The various background colors can be overridden with the following configuration:
Copy link
Contributor

Choose a reason for hiding this comment

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

passive –> active voice

Suggested change
The various background colors can be overridden with the following configuration:
You can override these background colors with the following theme configuration:

},
},
});
```

Material UI v6 users can use the `colorSchemes` property to specify different colors for light and dark mode:
Copy link
Contributor

Choose a reason for hiding this comment

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

might be nice to add h3s for ### Material UI v6 and ### Material UI v5 so users can quickly differentiate between the two samples when skimming

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change component: data grid This is the name of the generic UI component, not the React module! customization: theme Centered around the theming features design This is about UI or UX design, please involve a designer v8.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[data grid] Add a default background color to the data grid
5 participants