mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-01 03:29:39 +08:00
chore: Warning when FormItem use render props and name at same time (#20733)
This commit is contained in:
parent
4068f3d190
commit
40d9627554
@ -181,7 +181,16 @@ const FormItem: React.FC<FormItemProps> = (props: FormItemProps) => {
|
||||
warning(false, 'Form.Item', '`children` is array of render props cannot have `name`.');
|
||||
childNode = children;
|
||||
} else if (typeof children === 'function' && (!shouldUpdate || !!name)) {
|
||||
warning(false, 'Form.Item', '`children` of render props only work with `shouldUpdate`.');
|
||||
warning(
|
||||
!!shouldUpdate,
|
||||
'Form.Item',
|
||||
'`children` of render props only work with `shouldUpdate`.',
|
||||
);
|
||||
warning(
|
||||
!name,
|
||||
'Form.Item',
|
||||
"Do not use `name` with `children` of render props since it's not a field.",
|
||||
);
|
||||
} else if (!mergedName.length && !shouldUpdate && !dependencies) {
|
||||
childNode = children;
|
||||
} else if (React.isValidElement(children)) {
|
||||
|
@ -141,6 +141,18 @@ describe('Form', () => {
|
||||
'Warning: [antd: Form.Item] `children` of render props only work with `shouldUpdate`.',
|
||||
);
|
||||
});
|
||||
it('`name` should not work with render props', () => {
|
||||
mount(
|
||||
<Form>
|
||||
<Form.Item name="test" shouldUpdate>
|
||||
{() => null}
|
||||
</Form.Item>
|
||||
</Form>,
|
||||
);
|
||||
expect(errorSpy).toHaveBeenCalledWith(
|
||||
"Warning: [antd: Form.Item] Do not use `name` with `children` of render props since it's not a field.",
|
||||
);
|
||||
});
|
||||
it('children is array has name props', () => {
|
||||
mount(
|
||||
<Form>
|
||||
|
Loading…
Reference in New Issue
Block a user