mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-03 04:30:06 +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 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;
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user