-
-
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
[data grid] Pinned columns / rows color in dark mode looks like an accident #5979
Comments
Ideally, we should go for something that looks good on different dark themes. Maybe we can try a style for the pinned columns that focus on the borders only. |
So, if we list the options, we have:
|
About 1. Just to note that there is a slight difference between the two implementations: mui-plus was inspired by ag-grid for the overflow behavior, but it kept the position of the horizontal scrollbar of MUI X.
|
It seems like there's an issue with custom theme in MUI X: Here's And here's mui-x/packages/grid/x-data-grid-pro/src/components/DataGridProVirtualScroller.tsx Line 130 in c5cfc78
My guess is that we have more than 1 theme provider that messes it up |
@joserodolfofreitas it's actually the other way around - grey comes from default Material UI theme, not our custom docs theme. This is intentional The difference is that our demo sandbox doesn't use CssBaseline component, therefore there's no default background color. |
We could set background color on Grid root element (basically what @Janpot suggested in #5979 (comment)) --- a/packages/grid/x-data-grid/src/components/containers/GridRootStyles.ts
+++ b/packages/grid/x-data-grid/src/components/containers/GridRootStyles.ts
@@ -89,6 +89,7 @@ export const GridRootStyles = styled('div', {
height: '100%',
display: 'flex',
flexDirection: 'column',
+ backgroundColor: theme.palette.background.default,
[`&.${gridClasses.autoHeight}`]: {
height: 'auto',
[`& .${gridClasses['row--lastVisible']} .${gridClasses.cell}`]: { |
If the demos are supposed to render with the default theme, shouldn't we add a |
@Janpot This CSS baseline component is supposed to be optional. I think that it's important to be optional, it's designed so components can be progressively adopted in a codebase where you can't apply global resets. We later introduced So I think that there is a significant advantage of having it not present in the sandbox: it helps finding cases where we are missing a default style. |
how can it be optional in dark mode if it's responsible for providing the background? I've never not used |
Besides that, it won't make a difference in the demo anyway, because it only sets background color of |
@Janpot The use cases I'm considering with "progressive adoption" is: I have an existing application, build with Bootstrap/Tailwind CSS. I need a data grid/a date picker, I can't use MUI's CSS Baseline, it would break the rest of my application. The applications the component is added into would already be taking care of setting the background for the dark mode.
@cherniavskii Very ingesting option. A few thoughts:
|
Yep, progressive adoption makes sense. What I really wanted to get at is that the root of the issue here seems to be that we're missing a background in the demo sandbox.
One annoyance I could see with that is that if you want to put the DataGrid inside a |
@Janpot |
We can even do it in upcoming v6 :)
This is the current approach of highlighting pinned columns with a different background color.
Yeah, we can experiment with shadows and borders instead. @gerdadesign would you like to look into it? |
In the default dark mode, paper has a different background https://mui.com/material-ui/react-paper/#elevation |
But default theme is light, and to enable dark mode you have to create theme and use ThemeProvider. |
If the body background is My point was that one way to solve that is to wrap the DataGrid in its own ThemeProvider that sets the Ofcourse, with a transparent DataGrid, the problem goes away entirely. |
It seems like there are two parts at play here. There's the question of this demo in the screenshot not showing up as expected and there's also an ask to be able to customize the way pinned columns display with a border? Using shadows in light mode vs. different background color opacities in dark mode is how Material Design defines surfaces. In dark mode, shadows aren't as visible so they also adjusted the surface opacity. It still seems to me that the core issue of the pinned column backgrounds in the demos is that there is a mix of styles. With Material's reasoning, the pinned column would have two backgrounds — 1. the same background as the rest of the grid 2. the lower opacity white on top to show elevation. But with the grid's transparent background, this lower opacity overlay should be sitting on top of the page background color instead of the current black. I've created a few prototypes in Figma to show how I understand this is expected to work: This mockup defines two versions: 1. the background of the pinned column + grid against black and MUI's dark blue. 2. using only a border on the pinned column and transparent background. |
@gerdadesign Interesting, then I think that from "it looks like an accident", we could create a sub-issue that is about the default look & feel of Material UI. IMHO, the current one is not as optimal as it could be. I thought it was a bug. I'm expanding, when I look at the light mode, It feels like we want to use https://mui.com/material-ui/react-paper/#elevation. So when I look at the dark mode, I would expect the same: The above screenshot feels better on my end. Note that I have updated the background of the docs page only for the sake of feeling how it will be for end-users. It was implemented with: diff --git a/packages/grid/x-data-grid-pro/src/components/DataGridProColumnHeaders.tsx b/packages/grid/x-data-grid-pro/src/components/DataGridProColumnHeaders.tsx
index 6112388a9..2aa644d12 100644
--- a/packages/grid/x-data-grid-pro/src/components/DataGridProColumnHeaders.tsx
+++ b/packages/grid/x-data-grid-pro/src/components/DataGridProColumnHeaders.tsx
@@ -23,7 +23,7 @@ import {
GridPinnedPosition,
GridPinnedColumns,
} from '../hooks/features/columnPinning';
-import { filterColumns } from './DataGridProVirtualScroller';
+import { filterColumns, getBoxShadow } from './DataGridProVirtualScroller';
type OwnerState = {
classes?: DataGridProProcessedProps['classes'];
@@ -52,8 +52,9 @@ interface GridColumnHeadersPinnedColumnHeadersProps {
side: GridPinnedPosition;
}
-// Inspired by https://github.com/material-components/material-components-ios/blob/bca36107405594d5b7b16265a5b0ed698f85a5ee/components/Elevation/src/UIColor%2BMaterialElevation.m#L61
-const getOverlayAlpha = (elevation: number) => {
+// TODO: MUI Core should make this public
+// A clone of https://github.com/mui/material-ui/blob/ac8b1ef2e68799de77f4607fb36c13cb6c2da309/packages/mui-material/src/Paper/Paper.js#L12-L21
+export const getOverlayAlpha = (elevation: number): number => {
let alphaValue;
if (elevation < 1) {
alphaValue = 5.11916 * elevation ** 2;
@@ -78,16 +79,21 @@ const GridColumnHeadersPinnedColumnHeaders = styled('div', {
zIndex: 1,
display: 'flex',
flexDirection: 'column',
- boxShadow: theme.shadows[2],
backgroundColor: theme.palette.background.default,
...(theme.palette.mode === 'dark' && {
- backgroundImage: `linear-gradient(${alpha('#fff', getOverlayAlpha(2))}, ${alpha(
+ backgroundImage: `linear-gradient(${alpha('#fff', getOverlayAlpha(1))}, ${alpha(
'#fff',
- getOverlayAlpha(2),
+ getOverlayAlpha(1),
)})`,
}),
- ...(ownerState.side === GridPinnedPosition.left && { left: 0 }),
- ...(ownerState.side === GridPinnedPosition.right && { right: 0 }),
+ ...(ownerState.side === GridPinnedPosition.left && {
+ left: 0,
+ boxShadow: getBoxShadow(theme, ownerState.side),
+ }),
+ ...(ownerState.side === GridPinnedPosition.right && {
+ right: 0,
+ boxShadow: getBoxShadow(theme, ownerState.side),
+ }),
}));
interface DataGridProColumnHeadersProps extends React.HTMLAttributes<HTMLDivElement> {
diff --git a/packages/grid/x-data-grid-pro/src/components/DataGridProVirtualScroller.tsx b/packages/grid/x-data-grid-pro/src/components/DataGridProVirtualSc
roller.tsx
index 7acc3f904..a07c89ecb 100644
--- a/packages/grid/x-data-grid-pro/src/components/DataGridProVirtualScroller.tsx
+++ b/packages/grid/x-data-grid-pro/src/components/DataGridProVirtualScroller.tsx
@@ -97,9 +97,26 @@ const getOverlayAlpha = (elevation: number) => {
};
const getBoxShadowColor = (theme: Theme) => {
+ if (theme.palette.mode === 'dark') {
+ return '#000';
+ }
+
return alpha(theme.palette.common.black, 0.21);
};
+export const getBoxShadow = (theme: Theme, side: GridPinnedPosition) => {
+ const boxShadowColor = getBoxShadowColor(theme);
+ let boxShadow;
+
+ if (side === GridPinnedPosition.left) {
+ boxShadow = `2px 0px 4px -2px ${boxShadowColor}`;
+ } else if(side === GridPinnedPosition.right) {
+ boxShadow = `-2px 0px 4px -2px ${boxShadowColor}`;
+ }
+
+ return boxShadow;
+};
+
const VirtualScrollerDetailPanels = styled('div', {
name: 'MuiDataGrid',
slot: 'DetailPanels',
@@ -122,7 +139,6 @@ const VirtualScrollerPinnedColumns = styled('div', {
styles.pinnedColumns,
],
})<{ ownerState: VirtualScrollerPinnedColumnsProps }>(({ theme, ownerState }) => {
- const boxShadowColor = getBoxShadowColor(theme);
return {
position: 'sticky',
overflow: 'hidden',
@@ -132,12 +148,12 @@ const VirtualScrollerPinnedColumns = styled('div', {
...(ownerState.side === GridPinnedPosition.left && {
left: 0,
float: 'left',
- boxShadow: `2px 0px 4px -2px ${boxShadowColor}`,
+ boxShadow: getBoxShadow(theme, ownerState.side),
}),
...(ownerState.side === GridPinnedPosition.right && {
right: 0,
float: 'right',
- boxShadow: `-2px 0px 4px -2px ${boxShadowColor}`,
+ boxShadow: getBoxShadow(theme, ownerState.side),
}),
};
});
diff --git a/packages/grid/x-data-grid/src/components/containers/GridRootStyles.ts b/packages/grid/x-data-grid/src/components/containers/GridRootStyles.ts
index 086d6eff1..bd93d6cc5 100644
--- a/packages/grid/x-data-grid/src/components/containers/GridRootStyles.ts
+++ b/packages/grid/x-data-grid/src/components/containers/GridRootStyles.ts
@@ -90,6 +90,7 @@ export const GridRootStyles = styled('div', {
height: '100%',
display: 'flex',
flexDirection: 'column',
+ backgroundColor: theme.palette.background.default,
[`&.${gridClasses.autoHeight}`]: {
height: 'auto',
[`& .${gridClasses['row--lastVisible']} .${gridClasses.cell}`]: { The only limit is that the visual illusion doesn't work this well, on the edges that are at the border of the data grid. |
It doesn't seem to be the case anymore: https://mui.com/x/react-data-grid/column-pinning/ |
I thought so too but there is a subtle difference in color still 😅 I do think we should set a background color on the whole grid to avoid these cases. |
The problem isn't the color difference, it's that the hue/saturation doesn't match the background color. The color difference can be nice while we don't have the pinned shadows. |
Current behavior 😯
In dark mode, the background of the pinned columns is gray, and although it may work better in "blacker" backgrounds, it doesn't really match the theme we use in our demos.
Expected behavior 🤔
A different style to display pinned columns that better match different dark themes.
Steps to reproduce 🕹
Link to live example:
Steps:
Context 🔦
No response
Your environment 🌎
npx @mui/envinfo
Order ID 💳 (optional)
No response
The text was updated successfully, but these errors were encountered: