fix(Radio): Handle nesting correctly (#40741)

This commit is contained in:
JiaQi 2023-02-17 10:23:34 +08:00 committed by GitHub
parent 0aac2f0a05
commit 12a734adac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 6 deletions

View File

@ -36,13 +36,22 @@ describe('Radio', () => {
}); });
it('should use own disabled status first', () => { it('should use own disabled status first', () => {
const { container } = render( const { getByRole } = render(
<Form disabled> <Form disabled>
<Radio disabled={false} /> <Radio disabled={false} />
</Form>, </Form>,
); );
expect(container.querySelector('.ant-radio-wrapper')).not.toHaveClass( expect(getByRole('radio')).not.toBeDisabled();
'ant-radio-wrapper-disabled', });
it('should obtained correctly disabled status', () => {
const { getByRole } = render(
<Form disabled>
<Radio.Group disabled={false}>
<Radio />
</Radio.Group>
</Form>,
); );
expect(getByRole('radio')).not.toBeDisabled();
}); });
}); });

View File

@ -33,7 +33,6 @@ const InternalRadio: React.ForwardRefRenderFunction<HTMLElement, RadioProps> = (
rootClassName, rootClassName,
children, children,
style, style,
disabled: customDisabled,
...restProps ...restProps
} = props; } = props;
const radioPrefixCls = getPrefixCls('radio', customizePrefixCls); const radioPrefixCls = getPrefixCls('radio', customizePrefixCls);
@ -49,14 +48,15 @@ const InternalRadio: React.ForwardRefRenderFunction<HTMLElement, RadioProps> = (
// ===================== Disabled ===================== // ===================== Disabled =====================
const disabled = React.useContext(DisabledContext); const disabled = React.useContext(DisabledContext);
radioProps.disabled = customDisabled ?? disabled;
if (groupContext) { if (groupContext) {
radioProps.name = groupContext.name; radioProps.name = groupContext.name;
radioProps.onChange = onChange; radioProps.onChange = onChange;
radioProps.checked = props.value === groupContext.value; radioProps.checked = props.value === groupContext.value;
radioProps.disabled = radioProps.disabled || groupContext.disabled; radioProps.disabled = radioProps.disabled ?? groupContext.disabled;
} }
radioProps.disabled = radioProps.disabled ?? disabled;
const wrapperClassString = classNames( const wrapperClassString = classNames(
`${prefixCls}-wrapper`, `${prefixCls}-wrapper`,
{ {