mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 19:19:57 +08:00
fix(Radio): Handle nesting correctly (#40741)
This commit is contained in:
parent
0aac2f0a05
commit
12a734adac
@ -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();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -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`,
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user