Skip to content
Open
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
7 changes: 1 addition & 6 deletions packages/mui-system/src/createStyled/createStyled.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,8 @@ export default function createStyled(input = {}) {
? 'components'
: 'custom';

// if skipVariantsResolver option is defined, take the value, otherwise, true for root and false for other slots.
const skipVariantsResolver =
inputSkipVariantsResolver !== undefined
? inputSkipVariantsResolver
: // TODO v6: remove `Root` in the next major release
// For more details: https://github.com/mui/material-ui/pull/37908
(componentSlot && componentSlot !== 'Root' && componentSlot !== 'root') || false;
inputSkipVariantsResolver !== undefined ? inputSkipVariantsResolver : false;

const skipSx = inputSkipSx || false;

Expand Down
29 changes: 27 additions & 2 deletions packages/mui-system/src/styled/styled.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ describe('styled', () => {
});
});

it('variants should be skipped for non root slots', () => {
it('variants should apply to non-root slots by default', () => {
const TestSlot = styled('div', {
shouldForwardProp: (prop) => prop !== 'variant' && prop !== 'size' && prop !== 'sx',
name: 'MuiTest',
Expand All @@ -307,6 +307,31 @@ describe('styled', () => {
</ThemeProvider>,
);

expect(container.firstChild).toHaveComputedStyle({
width: '400px',
height: '400px',
});
});

it('variants should be skipped for non-root slots when skipVariantsResolver is true', () => {
const TestSlot = styled('div', {
shouldForwardProp: (prop) => prop !== 'variant' && prop !== 'size' && prop !== 'sx',
name: 'MuiTest',
slot: 'Slot',
skipVariantsResolver: true,
})`
width: 200px;
height: 300px;
`;

const { container } = render(
<ThemeProvider theme={theme}>
<TestSlot variant="rect" size="large">
Test
</TestSlot>
</ThemeProvider>,
);

expect(container.firstChild).toHaveComputedStyle({
width: '200px',
height: '300px',
Expand Down Expand Up @@ -337,7 +362,7 @@ describe('styled', () => {
});
});

it('variants should respect skipVariantsResolver if defined', () => {
it('variants should apply when skipVariantsResolver is explicitly false', () => {
const TestSlot = styled('div', {
shouldForwardProp: (prop) => prop !== 'variant' && prop !== 'size' && prop !== 'sx',
name: 'MuiTest',
Expand Down
Loading