Skip to content

Commit

Permalink
[Material UI] Update overridesResolver return from object to array …
Browse files Browse the repository at this point in the history
…of styles (#44752)
  • Loading branch information
siddhantantil39 authored Dec 13, 2024
1 parent 33490eb commit 68e3b40
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 33 deletions.
9 changes: 5 additions & 4 deletions packages/mui-material/src/Autocomplete/Autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,11 @@ const AutocompleteClearIndicator = styled(IconButton, {
const AutocompletePopupIndicator = styled(IconButton, {
name: 'MuiAutocomplete',
slot: 'PopupIndicator',
overridesResolver: ({ ownerState }, styles) => ({
...styles.popupIndicator,
...(ownerState.popupOpen && styles.popupIndicatorOpen),
}),
overridesResolver: (props, styles) => {
const { ownerState } = props;

return [styles.popupIndicator, ownerState.popupOpen && styles.popupIndicatorOpen];
},
})({
padding: 2,
marginRight: -2,
Expand Down
7 changes: 3 additions & 4 deletions packages/mui-material/src/AvatarGroup/AvatarGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ const useUtilityClasses = (ownerState) => {
const AvatarGroupRoot = styled('div', {
name: 'MuiAvatarGroup',
slot: 'Root',
overridesResolver: (props, styles) => ({
[`& .${avatarGroupClasses.avatar}`]: styles.avatar,
...styles.root,
}),
overridesResolver: (props, styles) => {
return [{ [`& .${avatarGroupClasses.avatar}`]: styles.avatar }, styles.root];
},
})(
memoTheme(({ theme }) => ({
display: 'flex',
Expand Down
12 changes: 7 additions & 5 deletions packages/mui-material/src/CardHeader/CardHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ const useUtilityClasses = (ownerState) => {
const CardHeaderRoot = styled('div', {
name: 'MuiCardHeader',
slot: 'Root',
overridesResolver: (props, styles) => ({
[`& .${cardHeaderClasses.title}`]: styles.title,
[`& .${cardHeaderClasses.subheader}`]: styles.subheader,
...styles.root,
}),
overridesResolver: (props, styles) => {
return [
{ [`& .${cardHeaderClasses.title}`]: styles.title },
{ [`& .${cardHeaderClasses.subheader}`]: styles.subheader },
styles.root,
];
},
})({
display: 'flex',
alignItems: 'center',
Expand Down
14 changes: 8 additions & 6 deletions packages/mui-material/src/FormControl/FormControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ const useUtilityClasses = (ownerState) => {
const FormControlRoot = styled('div', {
name: 'MuiFormControl',
slot: 'Root',
overridesResolver: ({ ownerState }, styles) => {
return {
...styles.root,
...styles[`margin${capitalize(ownerState.margin)}`],
...(ownerState.fullWidth && styles.fullWidth),
};
overridesResolver: (props, styles) => {
const { ownerState } = props;

return [
styles.root,
styles[`margin${capitalize(ownerState.margin)}`],
ownerState.fullWidth && styles.fullWidth,
];
},
})({
display: 'inline-flex',
Expand Down
13 changes: 7 additions & 6 deletions packages/mui-material/src/FormLabel/FormLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ const useUtilityClasses = (ownerState) => {
export const FormLabelRoot = styled('label', {
name: 'MuiFormLabel',
slot: 'Root',
overridesResolver: ({ ownerState }, styles) => {
return {
...styles.root,
...(ownerState.color === 'secondary' && styles.colorSecondary),
...(ownerState.filled && styles.filled),
};
overridesResolver: (props, styles) => {
const { ownerState } = props;
return [
styles.root,
ownerState.color === 'secondary' && styles.colorSecondary,
ownerState.filled && styles.filled,
];
},
})(
memoTheme(({ theme }) => ({
Expand Down
16 changes: 8 additions & 8 deletions packages/mui-material/src/styles/styled.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ describe('styled', () => {
},
});

const testOverridesResolver = (props, styles) => ({
...styles.root,
...(props.variant && styles[props.variant]),
});
const testOverridesResolver = (props, styles) => [
styles.root,
props.variant && styles[props.variant],
];

Test = styled('div', {
shouldForwardProp: (prop) => prop !== 'variant' && prop !== 'size' && prop !== 'sx',
Expand Down Expand Up @@ -429,10 +429,10 @@ describe('styled', () => {
});

it('should respect the skipSx option', () => {
const testOverridesResolver = (props, styles) => ({
...styles.root,
...(props.variant && styles[props.variant]),
});
const testOverridesResolver = (props, styles) => [
styles.root,
props.variant && styles[props.variant],
];

const TestNoSx = styled('div', {
shouldForwardProp: (prop) => prop !== 'variant' && prop !== 'size' && prop !== 'sx',
Expand Down

0 comments on commit 68e3b40

Please sign in to comment.