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', () => {
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
@ -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`,
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user