From 12a734adac24dd23a1f59b91a666a4a143447887 Mon Sep 17 00:00:00 2001 From: JiaQi <112228030+Yuiai01@users.noreply.github.com> Date: Fri, 17 Feb 2023 10:23:34 +0800 Subject: [PATCH] fix(Radio): Handle nesting correctly (#40741) --- components/radio/__tests__/radio.test.tsx | 15 ++++++++++++--- components/radio/radio.tsx | 6 +++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/components/radio/__tests__/radio.test.tsx b/components/radio/__tests__/radio.test.tsx index a0a35cb277..fe9b286d39 100644 --- a/components/radio/__tests__/radio.test.tsx +++ b/components/radio/__tests__/radio.test.tsx @@ -36,13 +36,22 @@ describe('Radio', () => { }); it('should use own disabled status first', () => { - const { container } = render( + const { getByRole } = render(
, ); - 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( +
+ + + +
, ); + expect(getByRole('radio')).not.toBeDisabled(); }); }); diff --git a/components/radio/radio.tsx b/components/radio/radio.tsx index fdd50c8870..c1a517d7e4 100644 --- a/components/radio/radio.tsx +++ b/components/radio/radio.tsx @@ -33,7 +33,6 @@ const InternalRadio: React.ForwardRefRenderFunction = ( rootClassName, children, style, - disabled: customDisabled, ...restProps } = props; const radioPrefixCls = getPrefixCls('radio', customizePrefixCls); @@ -49,14 +48,15 @@ const InternalRadio: React.ForwardRefRenderFunction = ( // ===================== 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`, {