mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-11-30 02:59:04 +08:00
feat: Warning invalidate element when using name
. (#20191)
This commit is contained in:
parent
3ef0a402b5
commit
ae88fdeabd
@ -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) {
|
||||
|
@ -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.',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user