diff --git a/packages/mui-material/src/Button/Button.js b/packages/mui-material/src/Button/Button.js index 37909a18464889..8e3c461417351e 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 { root: classesRoot, ...classes } = useUtilityClasses(ownerState); + const classes = useUtilityClasses(ownerState); const startIcon = startIconProp && ( @@ -339,7 +339,7 @@ const Button = React.forwardRef(function Button(inProps, ref) { return ( @@ -140,6 +143,10 @@ Checkbox.propTypes /* remove-proptypes */ = { * Override or extend the styles applied to the component. */ classes: PropTypes.object, + /** + * @ignore + */ + className: PropTypes.string, /** * The color of the component. * It supports both default and custom theme colors, which can be added as shown in the diff --git a/packages/mui-material/src/DialogContentText/DialogContentText.js b/packages/mui-material/src/DialogContentText/DialogContentText.js index 147992aaff4676..3af86c1590ba3d 100644 --- a/packages/mui-material/src/DialogContentText/DialogContentText.js +++ b/packages/mui-material/src/DialogContentText/DialogContentText.js @@ -1,5 +1,6 @@ import * as React from 'react'; import PropTypes from 'prop-types'; +import clsx from 'clsx'; import { unstable_composeClasses as composeClasses } from '@mui/base'; import styled, { rootShouldForwardProp } from '../styles/styled'; import useThemeProps from '../styles/useThemeProps'; @@ -30,7 +31,7 @@ const DialogContentTextRoot = styled(Typography, { const DialogContentText = React.forwardRef(function DialogContentText(inProps, ref) { const props = useThemeProps({ props: inProps, name: 'MuiDialogContentText' }); - const { children, ...ownerState } = props; + const { children, className, ...ownerState } = props; const classes = useUtilityClasses(ownerState); return ( @@ -40,6 +41,7 @@ const DialogContentText = React.forwardRef(function DialogContentText(inProps, r color="text.secondary" ref={ref} ownerState={ownerState} + className={clsx(classes.root, className)} {...props} classes={classes} /> @@ -59,6 +61,10 @@ DialogContentText.propTypes /* remove-proptypes */ = { * Override or extend the styles applied to the component. */ classes: PropTypes.object, + /** + * @ignore + */ + className: PropTypes.string, /** * The system prop that allows defining system overrides as well as additional CSS styles. */ diff --git a/packages/mui-material/src/InputLabel/InputLabel.js b/packages/mui-material/src/InputLabel/InputLabel.js index 6f255af7f7950e..a6af7ad1b3c423 100644 --- a/packages/mui-material/src/InputLabel/InputLabel.js +++ b/packages/mui-material/src/InputLabel/InputLabel.js @@ -1,6 +1,7 @@ import * as React from 'react'; import PropTypes from 'prop-types'; import { unstable_composeClasses as composeClasses } from '@mui/base'; +import clsx from 'clsx'; import formControlState from '../FormControl/formControlState'; import useFormControl from '../FormControl/useFormControl'; import FormLabel, { formLabelClasses } from '../FormLabel'; @@ -117,7 +118,14 @@ const InputLabelRoot = styled(FormLabel, { const InputLabel = React.forwardRef(function InputLabel(inProps, ref) { const props = useThemeProps({ name: 'MuiInputLabel', props: inProps }); - const { disableAnimation = false, margin, shrink: shrinkProp, variant, ...other } = props; + const { + disableAnimation = false, + margin, + shrink: shrinkProp, + variant, + className, + ...other + } = props; const muiFormControl = useFormControl(); @@ -143,11 +151,13 @@ const InputLabel = React.forwardRef(function InputLabel(inProps, ref) { }; const classes = useUtilityClasses(ownerState); + return ( @@ -167,6 +177,10 @@ InputLabel.propTypes /* remove-proptypes */ = { * Override or extend the styles applied to the component. */ classes: PropTypes.object, + /** + * @ignore + */ + className: PropTypes.string, /** * The color of the component. * It supports both default and custom theme colors, which can be added as shown in the diff --git a/packages/mui-material/src/InputLabel/InputLabel.test.js b/packages/mui-material/src/InputLabel/InputLabel.test.js index c1d5264b5582c4..44f140c4668552 100644 --- a/packages/mui-material/src/InputLabel/InputLabel.test.js +++ b/packages/mui-material/src/InputLabel/InputLabel.test.js @@ -6,6 +6,7 @@ import FormControl from '@mui/material/FormControl'; import Input from '@mui/material/Input'; import FormLabel from '@mui/material/FormLabel'; import InputLabel, { inputLabelClasses as classes } from '@mui/material/InputLabel'; +import { ClassNames } from '@emotion/react'; describe('', () => { const { render } = createRenderer(); @@ -119,4 +120,46 @@ describe('', () => { }); }); }); + + describe('Emotion compatibility', () => { + it('classes.root should overwrite built-in styles.', () => { + const text = 'The label'; + + const { getByText } = render( + + {({ css }) => ( + + {text} + + )} + , + ); + const label = getByText(text); + + expect(getComputedStyle(label).position).to.equal('static'); + }); + + it('className should overwrite classes.root and built-in styles.', () => { + const text = 'The label'; + + const { getByText } = render( + + {({ css }) => ( + + + {text} + + + )} + , + ); + const label = getByText(text); + + expect(getComputedStyle(label).position).to.equal('static'); + }); + }); }); diff --git a/packages/mui-material/src/ListItemButton/ListItemButton.js b/packages/mui-material/src/ListItemButton/ListItemButton.js index ecaf53caff0a14..33eb723f5d8094 100644 --- a/packages/mui-material/src/ListItemButton/ListItemButton.js +++ b/packages/mui-material/src/ListItemButton/ListItemButton.js @@ -136,6 +136,7 @@ const ListItemButton = React.forwardRef(function ListItemButton(inProps, ref) { divider = false, focusVisibleClassName, selected = false, + className, ...other } = props; @@ -180,6 +181,7 @@ const ListItemButton = React.forwardRef(function ListItemButton(inProps, ref) { component={(other.href || other.to) && component === 'div' ? 'a' : component} focusVisibleClassName={clsx(classes.focusVisible, focusVisibleClassName)} ownerState={ownerState} + className={clsx(classes.root, className)} {...other} classes={classes} > @@ -214,6 +216,10 @@ ListItemButton.propTypes /* remove-proptypes */ = { * Override or extend the styles applied to the component. */ classes: PropTypes.object, + /** + * @ignore + */ + className: PropTypes.string, /** * The component used for the root node. * Either a string to use a HTML element or a component. diff --git a/packages/mui-material/src/MenuItem/MenuItem.js b/packages/mui-material/src/MenuItem/MenuItem.js index 552064790c2cba..c2e9d7c47ad9fe 100644 --- a/packages/mui-material/src/MenuItem/MenuItem.js +++ b/packages/mui-material/src/MenuItem/MenuItem.js @@ -156,6 +156,7 @@ const MenuItem = React.forwardRef(function MenuItem(inProps, ref) { focusVisibleClassName, role = 'menuitem', tabIndex: tabIndexProp, + className, ...other } = props; @@ -202,6 +203,7 @@ const MenuItem = React.forwardRef(function MenuItem(inProps, ref) { tabIndex={tabIndex} component={component} focusVisibleClassName={clsx(classes.focusVisible, focusVisibleClassName)} + className={clsx(classes.root, className)} {...other} ownerState={ownerState} classes={classes} @@ -229,6 +231,10 @@ MenuItem.propTypes /* remove-proptypes */ = { * Override or extend the styles applied to the component. */ classes: PropTypes.object, + /** + * @ignore + */ + className: PropTypes.string, /** * The component used for the root node. * Either a string to use a HTML element or a component. diff --git a/packages/mui-material/src/Radio/Radio.js b/packages/mui-material/src/Radio/Radio.js index d13aeb6e3569b9..b0025a4dcd4a91 100644 --- a/packages/mui-material/src/Radio/Radio.js +++ b/packages/mui-material/src/Radio/Radio.js @@ -1,5 +1,6 @@ import * as React from 'react'; import PropTypes from 'prop-types'; +import clsx from 'clsx'; import { refType } from '@mui/utils'; import { unstable_composeClasses as composeClasses } from '@mui/base'; import { alpha } from '@mui/system'; @@ -86,6 +87,7 @@ const Radio = React.forwardRef(function Radio(inProps, ref) { name: nameProp, onChange: onChangeProp, size = 'medium', + className, ...other } = props; const ownerState = { @@ -123,6 +125,7 @@ const Radio = React.forwardRef(function Radio(inProps, ref) { checked={checked} onChange={onChange} ref={ref} + className={clsx(classes.root, className)} {...other} /> ); @@ -146,6 +149,10 @@ Radio.propTypes /* remove-proptypes */ = { * Override or extend the styles applied to the component. */ classes: PropTypes.object, + /** + * @ignore + */ + className: PropTypes.string, /** * The color of the component. * It supports both default and custom theme colors, which can be added as shown in the