Skip to content

Commit 1aa20fa

Browse files
[Radio] Fix inputProps not forwarded (@siriwatknp) (#45475)
1 parent 50a760e commit 1aa20fa

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

packages/mui-material/src/Radio/Radio.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ const Radio = React.forwardRef(function Radio(inProps, ref) {
127127
disableRipple = false,
128128
slots = {},
129129
slotProps = {},
130+
inputProps,
130131
...other
131132
} = props;
132133

@@ -166,6 +167,8 @@ const Radio = React.forwardRef(function Radio(inProps, ref) {
166167
}
167168
}
168169

170+
const externalInputProps = slotProps.input ?? inputProps;
171+
169172
const [RootSlot, rootSlotProps] = useSlot('root', {
170173
ref,
171174
elementType: RadioRoot,
@@ -197,7 +200,9 @@ const Radio = React.forwardRef(function Radio(inProps, ref) {
197200
slotProps: {
198201
// Do not forward `slotProps.root` again because it's already handled by the `RootSlot` in this file.
199202
input:
200-
typeof slotProps.input === 'function' ? slotProps.input(ownerState) : slotProps.input,
203+
typeof externalInputProps === 'function'
204+
? externalInputProps(ownerState)
205+
: externalInputProps,
201206
},
202207
},
203208
});

packages/mui-material/src/Radio/Radio.test.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import { expect } from 'chai';
3-
import { createRenderer } from '@mui/internal-test-utils';
3+
import { createRenderer, screen } from '@mui/internal-test-utils';
44
import Radio, { radioClasses as classes } from '@mui/material/Radio';
55
import FormControl from '@mui/material/FormControl';
66
import ButtonBase from '@mui/material/ButtonBase';
@@ -142,4 +142,10 @@ describe('<Radio />', () => {
142142
});
143143
});
144144
});
145+
146+
it('deprecated `inputProps` should work', () => {
147+
render(<Radio inputProps={{ 'aria-label': 'A' }} />);
148+
149+
expect(screen.queryByRole('radio', { name: 'A' })).not.to.equal(null);
150+
});
145151
});

0 commit comments

Comments
 (0)