Skip to content

Commit

Permalink
[Radio] Fix disabled state styling regression (#43592)
Browse files Browse the repository at this point in the history
  • Loading branch information
mnajdova authored Sep 9, 2024
1 parent 64aaf56 commit 98be46d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
23 changes: 20 additions & 3 deletions packages/mui-material/src/Radio/Radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SwitchBase from '../internal/SwitchBase';
import RadioButtonIcon from './RadioButtonIcon';
import capitalize from '../utils/capitalize';
import createChainedFunction from '../utils/createChainedFunction';
import useFormControl from '../FormControl/useFormControl';
import useRadioGroup from '../RadioGroup/useRadioGroup';
import radioClasses, { getRadioUtilityClass } from './radioClasses';
import rootShouldForwardProp from '../styles/rootShouldForwardProp';
Expand Down Expand Up @@ -51,7 +52,7 @@ const RadioRoot = styled(SwitchBase, {
},
variants: [
{
props: { color: 'default', disableRipple: false },
props: { color: 'default', disabled: false, disableRipple: false },
style: {
'&:hover': {
backgroundColor: theme.vars
Expand All @@ -63,7 +64,7 @@ const RadioRoot = styled(SwitchBase, {
...Object.entries(theme.palette)
.filter(([, palette]) => palette && palette.main)
.map(([color]) => ({
props: { color, disableRipple: false },
props: { color, disabled: false, disableRipple: false },
style: {
'&:hover': {
backgroundColor: theme.vars
Expand All @@ -75,7 +76,7 @@ const RadioRoot = styled(SwitchBase, {
...Object.entries(theme.palette)
.filter(([, palette]) => palette && palette.main)
.map(([color]) => ({
props: { color },
props: { color, disabled: false },
style: {
[`&.${radioClasses.checked}`]: {
color: (theme.vars || theme).palette[color].main,
Expand Down Expand Up @@ -121,11 +122,26 @@ const Radio = React.forwardRef(function Radio(inProps, ref) {
onChange: onChangeProp,
size = 'medium',
className,
disabled: disabledProp,
disableRipple = false,
...other
} = props;

const muiFormControl = useFormControl();

let disabled = disabledProp;

if (muiFormControl) {
if (typeof disabled === 'undefined') {
disabled = muiFormControl.disabled;
}
}

disabled ??= false;

const ownerState = {
...props,
disabled,
disableRipple,
color,
size,
Expand Down Expand Up @@ -154,6 +170,7 @@ const Radio = React.forwardRef(function Radio(inProps, ref) {
checkedIcon={React.cloneElement(checkedIcon, {
fontSize: defaultCheckedIcon.props.fontSize ?? size,
})}
disabled={disabled}
ownerState={ownerState}
classes={classes}
name={name}
Expand Down
31 changes: 31 additions & 0 deletions test/regressions/fixtures/Radio/RadioDisabledState.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as React from 'react';
import Radio from '@mui/material/Radio';

export default function RadioButtonsDisabled() {
const [selectedValue, setSelectedValue] = React.useState('a');

const handleChange = (event) => {
setSelectedValue(event.target.value);
};

return (
<div>
<Radio
disabled
checked={selectedValue === 'a'}
onChange={handleChange}
value="a"
name="radio-buttons"
inputProps={{ 'aria-label': 'A' }}
/>
<Radio
disabled
checked={selectedValue === 'b'}
onChange={handleChange}
value="b"
name="radio-buttons"
inputProps={{ 'aria-label': 'B' }}
/>
</div>
);
}

0 comments on commit 98be46d

Please sign in to comment.