mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-04 04:58:55 +08:00
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:
parent
dd8dd6062f
commit
4adc4df3e6
@ -19,12 +19,15 @@ export type ValidateStatus = typeof ValidateStatuses[number];
|
|||||||
type RenderChildren = (form: FormInstance) => React.ReactElement;
|
type RenderChildren = (form: FormInstance) => React.ReactElement;
|
||||||
type RcFieldProps = Omit<FieldProps, 'children'>;
|
type RcFieldProps = Omit<FieldProps, 'children'>;
|
||||||
|
|
||||||
export interface FormItemProps extends FormItemLabelProps, FormItemInputProps, RcFieldProps {
|
export interface FormItemProps
|
||||||
|
extends FormItemLabelProps,
|
||||||
|
FormItemInputProps,
|
||||||
|
Omit<RcFieldProps, 'children'> {
|
||||||
prefixCls?: string;
|
prefixCls?: string;
|
||||||
noStyle?: boolean;
|
noStyle?: boolean;
|
||||||
style?: React.CSSProperties;
|
style?: React.CSSProperties;
|
||||||
className?: string;
|
className?: string;
|
||||||
children: React.ReactElement | RenderChildren;
|
children: React.ReactElement | RenderChildren | React.ReactElement[];
|
||||||
id?: string;
|
id?: string;
|
||||||
hasFeedback?: boolean;
|
hasFeedback?: boolean;
|
||||||
validateStatus?: ValidateStatus;
|
validateStatus?: ValidateStatus;
|
||||||
@ -175,7 +178,10 @@ const FormItem: React.FC<FormItemProps> = (props: FormItemProps) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let childNode;
|
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`.');
|
warning(false, 'Form.Item', '`children` of render props only work with `shouldUpdate`.');
|
||||||
} else if (!mergedName.length && !shouldUpdate && !dependencies) {
|
} else if (!mergedName.length && !shouldUpdate && !dependencies) {
|
||||||
childNode = children;
|
childNode = children;
|
||||||
|
@ -137,6 +137,19 @@ describe('Form', () => {
|
|||||||
'Warning: [antd: Form.Item] `children` of render props only work with `shouldUpdate`.',
|
'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', () => {
|
describe('scrollToField', () => {
|
||||||
function test(name, genForm) {
|
function test(name, genForm) {
|
||||||
|
Loading…
Reference in New Issue
Block a user