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

[material-ui][AppBar] Fix inherit color is inconsistent between ThemeProvider and CssVarsProvider #42713

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
});
});
});
Loading