diff --git a/packages/form/src/BaseForm/createField.tsx b/packages/form/src/BaseForm/createField.tsx
index 3b0f6b62672a..6be62125ada5 100644
--- a/packages/form/src/BaseForm/createField.tsx
+++ b/packages/form/src/BaseForm/createField.tsx
@@ -180,7 +180,10 @@ function createField
(
);
};
-
+ // 标记是否是 proform 的组件
+ // @ts-ignore
+ // eslint-disable-next-line no-param-reassign
+ FieldWithContext.displayName = 'ProFormComponent';
return FieldWithContext as ProFormComponent
;
}
diff --git a/packages/form/src/components/DatePicker/index.tsx b/packages/form/src/components/DatePicker/index.tsx
index 82c51c1fce50..5c430b098cf1 100644
--- a/packages/form/src/components/DatePicker/index.tsx
+++ b/packages/form/src/components/DatePicker/index.tsx
@@ -15,5 +15,8 @@ ExportComponent.Week = ProFormDatePickerWeek;
ExportComponent.Month = ProFormDatePickerMonth;
ExportComponent.Quarter = ProFormDatePickerQuarter;
ExportComponent.Year = ProFormDatePickerYear;
+// @ts-ignore
+// eslint-disable-next-line no-param-reassign
+ExportComponent.displayName = 'ProFormComponent';
export default ExportComponent;
diff --git a/packages/form/src/components/Field/index.tsx b/packages/form/src/components/Field/index.tsx
index 8f45a62dcbee..12676351793e 100644
--- a/packages/form/src/components/Field/index.tsx
+++ b/packages/form/src/components/Field/index.tsx
@@ -73,13 +73,7 @@ const ProFormField: React.FC<
render={render as any}
renderFormItem={renderFormItem as any}
valueType={(valueType as 'text') || 'text'}
- fieldProps={{
- ...fieldProps,
- onChange: (...restParams: any) => {
- (fieldProps?.onChange as any)?.(...restParams);
- onChange?.(...restParams);
- },
- }}
+ fieldProps={fieldProps}
valueEnum={runFunction(valueEnum)}
{...proFieldProps}
{...restProps}
diff --git a/packages/form/src/components/FieldSet/index.tsx b/packages/form/src/components/FieldSet/index.tsx
index 3df52ffd9fc8..a5bed683186a 100644
--- a/packages/form/src/components/FieldSet/index.tsx
+++ b/packages/form/src/components/FieldSet/index.tsx
@@ -32,6 +32,7 @@ const FieldSet: React.FC = ({
value = [],
valuePropName,
onChange,
+ fieldProps,
space,
type = 'space',
}) => {
@@ -39,6 +40,7 @@ const FieldSet: React.FC = ({
const newValues = [...value];
newValues[index] = defaultGetValueFromEvent(valuePropName || 'value', fileValue);
onChange?.(newValues);
+ fieldProps?.onChange?.(newValues);
};
let itemIndex = -1;
@@ -46,24 +48,34 @@ const FieldSet: React.FC = ({
if (React.isValidElement(item)) {
itemIndex += 1;
const index = itemIndex;
- return React.cloneElement(item, {
- key: index,
- ignoreFormItem: true,
- ...((item.props as any) || {}),
- fieldProps: {
- ...(item?.props as any)?.fieldProps,
- onChange: (...restParams: any) => {
- (item.props as any)?.fieldProps?.onChange?.(...restParams);
- (item.props as any)?.onChange?.(...restParams);
- fieldSetOnChange(restParams[0], index);
- },
- },
- value: value[index],
- onChange: (itemValue: any) => {
- fieldSetOnChange(itemValue, index);
- (item as any).props.onChange?.(itemValue);
- },
- });
+ const isProFromItem =
+ // @ts-ignore
+ item?.type?.displayName === 'ProFormComponent' || item?.props?.readonly;
+ const forkProps = isProFromItem
+ ? {
+ key: index,
+ ignoreFormItem: true,
+ ...((item.props as any) || {}),
+ // 如果不是我们自定义的组件 fieldProps 无法识别
+ fieldProps: {
+ ...(item?.props as any)?.fieldProps,
+ onChange: (...restParams: any) => {
+ fieldSetOnChange(restParams[0], index);
+ },
+ },
+ value: value[index],
+ onChange: undefined,
+ }
+ : {
+ key: index,
+ ...((item.props as any) || {}),
+ value: value[index],
+ onChange: (itemValue: any) => {
+ fieldSetOnChange(itemValue, index);
+ (item as any).props.onChange?.(itemValue);
+ },
+ };
+ return React.cloneElement(item, forkProps);
}
return item;
});
@@ -72,7 +84,7 @@ const FieldSet: React.FC = ({
/** Input.Group 需要配置 compact */
const typeProps = { ...(type === 'group' ? { compact: true } : {}) };
return (
-
+
{list}
);
@@ -82,7 +94,14 @@ const ProFormFieldSet: React.FC = React.fo
({ children, space, valuePropName, ...rest }, ref) => {
useImperativeHandle(ref, () => {}, []);
return (
-