Skip to content

Commit

Permalink
[material-ui][AppBar] Fix inherit color is inconsistent between Theme…
Browse files Browse the repository at this point in the history
…Provider and CssVarsProvider (#42713)
  • Loading branch information
ZeeshanTamboli committed Jul 11, 2024
1 parent 3a920ad commit 7c65f7c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/mui-material/src/AppBar/AppBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ const AppBarRoot = styled(Paper, {
theme.vars.palette[ownerState.color].contrastText,
),
}),
backgroundColor: 'var(--AppBar-background)',
...(!['inherit', 'transparent'].includes(ownerState.color) && {
backgroundColor: 'var(--AppBar-background)',
}),
color: ownerState.color === 'inherit' ? 'inherit' : 'var(--AppBar-color)',
...(ownerState.color === 'transparent' && {
backgroundImage: 'none',
Expand Down
44 changes: 44 additions & 0 deletions packages/mui-material/src/AppBar/AppBar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import { expect } from 'chai';
import { createRenderer, screen } from '@mui-internal/test-utils';
import AppBar, { appBarClasses as classes } from '@mui/material/AppBar';
import Paper from '@mui/material/Paper';
import {
ThemeProvider,
Experimental_CssVarsProvider as CssVarsProvider,
hexToRgb,
} from '@mui/material/styles';
import defaultTheme from '../styles/defaultTheme';
import describeConformance from '../../test/describeConformance';

describe('<AppBar />', () => {
Expand Down Expand Up @@ -62,4 +68,42 @@ describe('<AppBar />', () => {
expect(appBar).to.have.class('mui-fixed');
});
});

it('should inherit Paper background color with ThemeProvider', function test() {
if (/jsdom/.test(window.navigator.userAgent)) {
this.skip();
}

render(
<ThemeProvider theme={defaultTheme}>
<AppBar data-testid="root" color="inherit">
Hello World
</AppBar>
</ThemeProvider>,
);

const appBar = screen.getByTestId('root');
expect(appBar).toHaveComputedStyle({
backgroundColor: hexToRgb(defaultTheme.palette.background.paper),
});
});

it('should inherit Paper background color with CssVarsProvider', function test() {
if (/jsdom/.test(window.navigator.userAgent)) {
this.skip();
}

render(
<CssVarsProvider>
<AppBar data-testid="root" color="inherit">
Hello World
</AppBar>
</CssVarsProvider>,
);

const appBar = screen.getByTestId('root');
expect(appBar).toHaveComputedStyle({
backgroundColor: hexToRgb(defaultTheme.palette.background.paper),
});
});
});

0 comments on commit 7c65f7c

Please sign in to comment.