feat: Warning invalidate element when using name. (#20191)

This commit is contained in:
二货机器人 2019-12-11 16:08:59 +08:00 committed by GitHub
parent 3ef0a402b5
commit ae88fdeabd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -188,6 +188,13 @@ const FormItem: React.FC<FormItemProps> = (props: FormItemProps) => {
childNode = React.cloneElement(children, childProps);
} else if (typeof children === 'function' && shouldUpdate && !name) {
childNode = children(context);
} else {
warning(
!mergedName.length,
'Form.Item',
'`name` is only used for validate React element. If you are using Form.Item as layout display, please remove `name` instead.',
);
childNode = children;
}
if (noStyle) {

View File

@ -196,4 +196,15 @@ describe('Form', () => {
);
expect(wrapper.render()).toMatchSnapshot();
});
it('warning when use `name` but children is not validate element', () => {
mount(
<Form>
<Form.Item name="warning">text</Form.Item>
</Form>,
);
expect(errorSpy).toHaveBeenCalledWith(
'Warning: [antd: Form.Item] `name` is only used for validate React element. If you are using Form.Item as layout display, please remove `name` instead.',
);
});
});