fix: form item array children interface (#20577)

* Update Form.tsx

* Update Form.tsx

* fix: fix formItem array children interface

* fix: array

* feat: test
This commit is contained in:
叶枫 2020-01-01 20:07:10 +08:00 committed by 二货机器人
parent dd8dd6062f
commit 4adc4df3e6
2 changed files with 22 additions and 3 deletions

View File

@ -19,12 +19,15 @@ export type ValidateStatus = typeof ValidateStatuses[number];
type RenderChildren = (form: FormInstance) => React.ReactElement;
type RcFieldProps = Omit<FieldProps, 'children'>;
export interface FormItemProps extends FormItemLabelProps, FormItemInputProps, RcFieldProps {
export interface FormItemProps
extends FormItemLabelProps,
FormItemInputProps,
Omit<RcFieldProps, 'children'> {
prefixCls?: string;
noStyle?: boolean;
style?: React.CSSProperties;
className?: string;
children: React.ReactElement | RenderChildren;
children: React.ReactElement | RenderChildren | React.ReactElement[];
id?: string;
hasFeedback?: boolean;
validateStatus?: ValidateStatus;
@ -175,7 +178,10 @@ const FormItem: React.FC<FormItemProps> = (props: FormItemProps) => {
};
let childNode;
if (typeof children === 'function' && (!shouldUpdate || !!name)) {
if (Array.isArray(children) && !!name) {
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`.');
} else if (!mergedName.length && !shouldUpdate && !dependencies) {
childNode = children;

View File

@ -137,6 +137,19 @@ describe('Form', () => {
'Warning: [antd: Form.Item] `children` of render props only work with `shouldUpdate`.',
);
});
it('children is array has name props', () => {
mount(
<Form>
<Form.Item name="test">
<div>one</div>
<div>two</div>
</Form.Item>
</Form>,
);
expect(errorSpy).toHaveBeenCalledWith(
'Warning: [antd: Form.Item] `children` is array of render props cannot have `name`.',
);
});
describe('scrollToField', () => {
function test(name, genForm) {