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

Outlined variants of paper have wrong background-color in dark-mode when resting on an elevated paper #28408

Open
MrEbbinghaus opened this issue Sep 17, 2021 · 5 comments
Labels
component: Paper This is the name of the generic UI component, not the React module! new feature New feature or request

Comments

@MrEbbinghaus
Copy link

MrEbbinghaus commented Sep 17, 2021

tl;dr
I propose to respect the elevation prop for outlined variants of paper with regard to the background color. (Paper becoming lighter with elevation)


An outlined paper sitting on top of an elevated paper should have a relative elevation of 0.
In the current implementation, the elevation of outlined paper is absolute.

In light mode, this is fine, since the background color doesn't change.

In dark mode, paper(/material) gets lighter the higher it is.
But since an outlined paper is always at elevation 0, the background color won't get lighter.

This leads to outlined variants "punching a hole" into the paper it is resting on:
image

How it should look like:
image

Possible ways of dealing with this issue

(First the more complicated, but more general solution.

  1. Properly stacking of paper.
    Keep track of the current absolute elevation of a sheet of paper based on the elevation the paper is sitting on, and setting the background color based on that.
    I don't know how best to accomplish this. Ideas on how to do this:
    • Nested CSS
    • Keeping an elevation context
    • Using a transparent background.

This would solve the problem of non-outlined paper on paper, which is currently wrong as well.
(However, for non-outlined paper, this is less of a problem, as you can manually set the elevation prop to fix this issue)

image

  1. The easy workaround:
    Respect the elevation prop for outlined variants with regard to the background color.
    (This does not have to be a dark mode exclusive solution.)

Related:
#21748 #18309

@MrEbbinghaus MrEbbinghaus added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Sep 17, 2021
@MrEbbinghaus
Copy link
Author

MrEbbinghaus commented Sep 17, 2021

Change https://github.com/mui-org/material-ui/blob/master/packages/mui-material/src/Paper/Paper.js#L38 to:

const PaperRoot = styled('div', {
  name: 'MuiPaper',
  slot: 'Root',
  overridesResolver: (props, styles) => {
    const { ownerState } = props;

    return [
      styles.root,
      styles[ownerState.variant],
      !ownerState.square && styles.rounded,
      styles[`elevation${ownerState.elevation}`],                    // <- Change here
    ];
  },
})(({ theme, ownerState }) => ({
  backgroundColor: theme.palette.background.paper,
  color: theme.palette.text.primary,
  transition: theme.transitions.create('box-shadow'),
  ...(!ownerState.square && {
    borderRadius: theme.shape.borderRadius,
  }),
  ...(ownerState.variant === 'outlined' && {
    border: `1px solid ${theme.palette.divider}`,
  }),
  ...(ownerState.variant === 'elevation' && {
    boxShadow: theme.shadows[ownerState.elevation],
  }),
  ...(theme.palette.mode === 'dark' && {                                // <- Change here
    backgroundImage: `linear-gradient(${alpha(
      '#fff',
      getOverlayAlpha(ownerState.elevation),
    )}, ${alpha('#fff', getOverlayAlpha(ownerState.elevation))})`,
  }),
}));

This would do the trick, wouldn't it?
(I would open a PR with this, but I am not really a Javascript Dev, and I am not familiar with this project.)

@MrEbbinghaus MrEbbinghaus changed the title Outlined variants of paper have wrong background color when not on background Outlined variants of paper have wrong background-color in dark-mode when resting on an elevated paper Sep 17, 2021
@eps1lon eps1lon added component: Paper This is the name of the generic UI component, not the React module! new feature New feature or request and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Sep 18, 2021
@ashfaqnisar
Copy link

Hey @MrEbbinghaus,
Was having the same issue with the paper component. The colour was becoming lighter than the colour I provided.
The colour provided to the component was #1d1d1d but it was turning into #2c2c2c

I have added images for reference.
Present Behaviour:
image

Expected Behaviour:
image

For the workaround, I removed the background image style on the paper by overriding it.

image

@Cristy94
Copy link

Cristy94 commented May 11, 2023

Any updates? The paper color in dark mode is different after upgrading, even with backgroundImage set to none

v4:
Paper background is: #424242
image

v5:
Paper background is: #121212
image

Edit: as a fix, I manually set the paper background to '#424242':

const darkPalette: PaletteOptions = {
    mode: 'dark',
    primary: {
        main: '#35a8d4',
    },
    background: {
        default: '#222',
        paper: '#424242',
    },
    secondary: {
        main: '#e656d4',
    }
};

Seems to be mentioned here: https://mui.com/material-ui/migration/v5-component-changes/#default-background-colors

I am still trying to figure out why some text is still not changed from black to white in dark mode.

@MrEbbinghaus
Copy link
Author

@eps1lon You tagged this issue with new feature. I would rather categorize this as a bug and design: material, as it "violates" the material2 guidelines.

@Zamlos
Copy link

Zamlos commented Aug 28, 2023

Exact same issue. If you accumulate paper over paper (all of them transparent), the ones on top gets clearer and clearer.

Captura de pantalla 2023-08-28 a las 19 31 12

I am using MUI material v 5.11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: Paper This is the name of the generic UI component, not the React module! new feature New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants