diff --git a/packages/mui-material/src/Badge/Badge.js b/packages/mui-material/src/Badge/Badge.js index 6123733758546f..731c7a5af48a77 100644 --- a/packages/mui-material/src/Badge/Badge.js +++ b/packages/mui-material/src/Badge/Badge.js @@ -258,7 +258,7 @@ const Badge = React.forwardRef(function Badge(inProps, ref) { Badge: BadgeBadge, ...components, }} - className={clsx(className, classes.root, componentsProps.root?.className)} + className={clsx(componentsProps.root?.className, classes.root, className)} componentsProps={{ root: { ...componentsProps.root, diff --git a/packages/mui-material/src/Button/Button.js b/packages/mui-material/src/Button/Button.js index 46e08ee91794ad..37909a18464889 100644 --- a/packages/mui-material/src/Button/Button.js +++ b/packages/mui-material/src/Button/Button.js @@ -322,7 +322,7 @@ const Button = React.forwardRef(function Button(inProps, ref) { variant, }; - const classes = useUtilityClasses(ownerState); + const { root: classesRoot, ...classes } = useUtilityClasses(ownerState); const startIcon = startIconProp && ( @@ -339,7 +339,7 @@ const Button = React.forwardRef(function Button(inProps, ref) { return ( ', () => { const { render, renderToString } = createRenderer(); @@ -634,4 +635,64 @@ describe(' + )} + , + ); + const button = getByRole('button'); + + expect(getComputedStyle(button).color).to.equal(color); + }); + + it('className should overwrite classes.root and builtin styles.', () => { + const colorPink = 'rgb(255, 192, 204)'; + const colorRed = 'rgb(255, 0, 0)'; + + const { getByRole } = render( + + {({ css }) => ( + + )} + , + ); + const button = getByRole('button'); + + expect(getComputedStyle(button).color).to.equal(colorRed); + }); + + it('classes.* should overwrite builtin styles.', () => { + // This is pink + const color = 'rgb(255, 192, 204)'; + + const { getByRole } = render( + + {({ css }) => ( + + )} + , + ); + const button = getByRole('button'); + + expect(getComputedStyle(button).color).to.equal(color); + }); + }); }); diff --git a/packages/mui-material/src/ButtonBase/TouchRipple.js b/packages/mui-material/src/ButtonBase/TouchRipple.js index e192ea8f1907da..2e299b19d0b3b0 100644 --- a/packages/mui-material/src/ButtonBase/TouchRipple.js +++ b/packages/mui-material/src/ButtonBase/TouchRipple.js @@ -305,7 +305,7 @@ const TouchRipple = React.forwardRef(function TouchRipple(inProps, ref) { return ( diff --git a/packages/mui-material/src/Select/SelectInput.js b/packages/mui-material/src/Select/SelectInput.js index e1d13d6502c31e..81f92e9c4942d1 100644 --- a/packages/mui-material/src/Select/SelectInput.js +++ b/packages/mui-material/src/Select/SelectInput.js @@ -518,7 +518,7 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) { onFocus={onFocus} {...SelectDisplayProps} ownerState={ownerState} - className={clsx(classes.select, className, SelectDisplayProps.className)} + className={clsx(SelectDisplayProps.className, classes.select, className)} // The id is required for proper a11y id={buttonId} > diff --git a/packages/mui-utils/src/composeClasses/composeClasses.test.ts b/packages/mui-utils/src/composeClasses/composeClasses.test.ts index 61af819b25efc8..310c217bf8414a 100644 --- a/packages/mui-utils/src/composeClasses/composeClasses.test.ts +++ b/packages/mui-utils/src/composeClasses/composeClasses.test.ts @@ -32,8 +32,8 @@ describe('composeClasses', () => { }, ), ).to.deep.equal({ - root: 'MuiTest-root standardOverride MuiTest-standard', - slot: 'slotOverride MuiTest-slot', + root: 'MuiTest-root MuiTest-standard standardOverride', + slot: 'MuiTest-slot slotOverride', }); }); @@ -51,8 +51,8 @@ describe('composeClasses', () => { }, ), ).to.deep.equal({ - root: 'MuiTest-root standardOverride MuiTest-standard', - slot: 'slotOverride MuiTest-slot', + root: 'MuiTest-root MuiTest-standard standardOverride', + slot: 'MuiTest-slot slotOverride', }); }); }); diff --git a/packages/mui-utils/src/composeClasses/composeClasses.ts b/packages/mui-utils/src/composeClasses/composeClasses.ts index 633f38d55d1d2e..5b4726e208699a 100644 --- a/packages/mui-utils/src/composeClasses/composeClasses.ts +++ b/packages/mui-utils/src/composeClasses/composeClasses.ts @@ -12,10 +12,10 @@ export default function composeClasses( output[slot] = slots[slot] .reduce((acc, key) => { if (key) { + acc.push(getUtilityClass(key)); if (classes && classes[key]) { acc.push(classes[key]); } - acc.push(getUtilityClass(key)); } return acc; }, [] as string[]) diff --git a/test/regressions/fixtures/Button/EmotionCompat.js b/test/regressions/fixtures/Button/EmotionCompat.js new file mode 100644 index 00000000000000..e7734695b6e496 --- /dev/null +++ b/test/regressions/fixtures/Button/EmotionCompat.js @@ -0,0 +1,27 @@ +import * as React from 'react'; +import { ClassNames } from '@emotion/react'; +import Button from '@mui/material/Button'; + +export default function EmotionCompat() { + return ( + + {({ css }) => ( + + + + + + )} + + ); +}