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', () => {
const { container } = render(
const { getByRole } = render(
<Form disabled>
<Radio disabled={false} />
</Form>,
);
expect(container.querySelector('.ant-radio-wrapper')).not.toHaveClass(
'ant-radio-wrapper-disabled',
expect(getByRole('radio')).not.toBeDisabled();
});
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,
children,
style,
disabled: customDisabled,
...restProps
} = props;
const radioPrefixCls = getPrefixCls('radio', customizePrefixCls);
@ -49,14 +48,15 @@ const InternalRadio: React.ForwardRefRenderFunction<HTMLElement, RadioProps> = (
// ===================== Disabled =====================
const disabled = React.useContext(DisabledContext);
radioProps.disabled = customDisabled ?? disabled;
if (groupContext) {
radioProps.name = groupContext.name;
radioProps.onChange = onChange;
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(
`${prefixCls}-wrapper`,
{