Skip to content

Commit

Permalink
[Radio] Fix inputProps not forwarded (@siriwatknp) (#45475)
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Mar 5, 2025
1 parent 50a760e commit 1aa20fa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion packages/mui-material/src/Radio/Radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const Radio = React.forwardRef(function Radio(inProps, ref) {
disableRipple = false,
slots = {},
slotProps = {},
inputProps,
...other
} = props;

Expand Down Expand Up @@ -166,6 +167,8 @@ const Radio = React.forwardRef(function Radio(inProps, ref) {
}
}

const externalInputProps = slotProps.input ?? inputProps;

const [RootSlot, rootSlotProps] = useSlot('root', {
ref,
elementType: RadioRoot,
Expand Down Expand Up @@ -197,7 +200,9 @@ const Radio = React.forwardRef(function Radio(inProps, ref) {
slotProps: {
// Do not forward `slotProps.root` again because it's already handled by the `RootSlot` in this file.
input:
typeof slotProps.input === 'function' ? slotProps.input(ownerState) : slotProps.input,
typeof externalInputProps === 'function'
? externalInputProps(ownerState)
: externalInputProps,
},
},
});
Expand Down
8 changes: 7 additions & 1 deletion packages/mui-material/src/Radio/Radio.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { expect } from 'chai';
import { createRenderer } from '@mui/internal-test-utils';
import { createRenderer, screen } from '@mui/internal-test-utils';
import Radio, { radioClasses as classes } from '@mui/material/Radio';
import FormControl from '@mui/material/FormControl';
import ButtonBase from '@mui/material/ButtonBase';
Expand Down Expand Up @@ -142,4 +142,10 @@ describe('<Radio />', () => {
});
});
});

it('deprecated `inputProps` should work', () => {
render(<Radio inputProps={{ 'aria-label': 'A' }} />);

expect(screen.queryByRole('radio', { name: 'A' })).not.to.equal(null);
});
});

0 comments on commit 1aa20fa

Please sign in to comment.