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

[system] Merge props and ownerState in the variants props callback #41219

Merged
Merged
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
32 changes: 32 additions & 0 deletions test/integration/mui-system/createStyled.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,38 @@ describe('createStyled', () => {
expect(getByTestId('red')).toHaveComputedStyle({ backgroundColor: 'rgb(255, 0, 0)' });
});

it('should merge props and ownerState in props callback', () => {
const styled = createStyled({
defaultTheme: {
colors: { blue: 'rgb(0, 0, 255)', red: 'rgb(255, 0, 0)', green: 'rgb(0, 255, 0)' },
},
});

const Test = styled('div')(({ theme, color }) => ({
variants: [
{
props: (props) => props.color === 'green' || props.color === 'red',
style: {
backgroundColor: theme.colors[color],
},
},
],
}));

const { getByTestId } = render(
<React.Fragment>
<Test data-testid="red" ownerState={{ color: 'red' }}>
Red
</Test>
<Test data-testid="green" ownerState={{ color: 'green' }}>
Green
</Test>
</React.Fragment>,
);
expect(getByTestId('green')).toHaveComputedStyle({ backgroundColor: 'rgb(0, 255, 0)' });
expect(getByTestId('red')).toHaveComputedStyle({ backgroundColor: 'rgb(255, 0, 0)' });
});

it('should accept variants in arrays', () => {
const styled = createStyled({ defaultTheme: { colors: { blue: 'rgb(0, 0, 255)' } } });

Expand Down
Loading