Skip to content

Commit

Permalink
[material-ui][Paper] Fix wrong background-image on Paper when elevati…
Browse files Browse the repository at this point in the history
…on is 0 (#43723)
  • Loading branch information
ZeeshanTamboli authored Sep 13, 2024
1 parent 9a78191 commit f403201
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 88 deletions.
35 changes: 34 additions & 1 deletion packages/mui-material/src/Paper/Paper.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import * as React from 'react';
import { expect } from 'chai';
import PropTypes from 'prop-types';
import { createRenderer, strictModeDoubleLoggingSuppressed } from '@mui/internal-test-utils';
import {
createRenderer,
strictModeDoubleLoggingSuppressed,
screen,
} from '@mui/internal-test-utils';
import Paper, { paperClasses as classes } from '@mui/material/Paper';
import { createTheme, ThemeProvider } from '@mui/material/styles';
import describeConformance from '../../test/describeConformance';
Expand Down Expand Up @@ -110,4 +114,33 @@ describe('<Paper />', () => {
]);
});
});

it('should have no boxShadow or background-image on Paper with elevation 0 in dark mode using CSS variables', function test() {
if (/jsdom/.test(window.navigator.userAgent)) {
this.skip();
}

const theme = createTheme({
cssVariables: true,
colorSchemes: {
dark: true,
},
defaultColorScheme: 'dark',
});

render(
<ThemeProvider theme={theme}>
<Paper data-testid="parent" elevation={23}>
elevation=23
<Paper data-testid="child" elevation={0} />
</Paper>
</ThemeProvider>,
);

const childPaper = screen.getByTestId('child');
expect(childPaper).toHaveComputedStyle({
boxShadow: 'none',
backgroundImage: 'none',
});
});
});
2 changes: 1 addition & 1 deletion packages/mui-material/src/styles/createColorScheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import getOverlayAlpha from './getOverlayAlpha';

const defaultDarkOverlays = [...Array(25)].map((_, index) => {
if (index === 0) {
return undefined;
return 'none';
}
const overlay = getOverlayAlpha(index);
return `linear-gradient(rgba(255 255 255 / ${overlay}), rgba(255 255 255 / ${overlay}))`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import excludeVariablesFromRoot from './excludeVariablesFromRoot';

describe('excludeVariablesFromRoot', () => {
it('should return true', () => {
expect(excludeVariablesFromRoot('mui').includes(`--mui-overlays-0`)).to.equal(true);
expect(excludeVariablesFromRoot('mui').includes(`--mui-overlays-1`)).to.equal(true);
expect(excludeVariablesFromRoot('mui').includes(`--mui-overlays-2`)).to.equal(true);
expect(excludeVariablesFromRoot('mui').includes(`--mui-overlays-3`)).to.equal(true);
Expand Down
4 changes: 2 additions & 2 deletions packages/mui-material/src/styles/excludeVariablesFromRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @internal These variables should not appear in the :root stylesheet when the `defaultColorScheme="dark"`
*/
const excludeVariablesFromRoot = (cssVarPrefix?: string) => [
...[...Array(24)].map(
(_, index) => `--${cssVarPrefix ? `${cssVarPrefix}-` : ''}overlays-${index + 1}`,
...[...Array(25)].map(
(_, index) => `--${cssVarPrefix ? `${cssVarPrefix}-` : ''}overlays-${index}`,
),
`--${cssVarPrefix ? `${cssVarPrefix}-` : ''}palette-AppBar-darkBg`,
`--${cssVarPrefix ? `${cssVarPrefix}-` : ''}palette-AppBar-darkColor`,
Expand Down
4 changes: 2 additions & 2 deletions packages/mui-material/src/styles/extendTheme.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,14 @@ describe('extendTheme', () => {
const theme = extendTheme({ defaultColorScheme: 'dark' });
expect(theme.colorSchemes.dark.overlays).to.have.length(25);

expect(theme.colorSchemes.dark.overlays[0]).to.equal(undefined);
expect(theme.colorSchemes.dark.overlays[0]).to.equal('none');
expect(theme.colorSchemes.dark.overlays[24]).to.equal(
'linear-gradient(rgba(255 255 255 / 0.165), rgba(255 255 255 / 0.165))',
);
});

it('should override the array as expected', () => {
const overlays = Array(24).fill('none');
const overlays = Array(25).fill('none');
const theme = extendTheme({
defaultColorScheme: 'dark',
colorSchemes: { dark: { overlays } },
Expand Down
Loading

0 comments on commit f403201

Please sign in to comment.