Skip to content

Commit

Permalink
fix(form): FieldSet igrone no Element
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuai2144 committed Nov 17, 2020
1 parent a181f48 commit aa40d77
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
29 changes: 17 additions & 12 deletions packages/form/src/components/FieldSet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,24 @@ const FieldSet: React.FC<ProFromFieldSetProps> = ({
onChange?.(newValues);
};

const list = toArray(children).map((item, index) => {
return React.cloneElement(item, {
key: index,
ignoreFormItem: true,
...item.props,
value: value[index],
onChange: (itemValue: any) => {
fieldSetOnChange(itemValue, index);
item.props.onChange?.(itemValue);
},
});
let itemIndex = -1;
const list = toArray(children).map((item: any) => {
if (React.isValidElement(item)) {
itemIndex += 1;
const index = itemIndex;
return React.cloneElement(item, {
key: index,
ignoreFormItem: true,
...((item.props as any) || {}),
value: value[index],
onChange: (itemValue: any) => {
fieldSetOnChange(itemValue, index);
(item as any).props.onChange?.(itemValue);
},
});
}
return item;
});

return <Space {...space}>{list}</Space>;
};

Expand Down
2 changes: 2 additions & 0 deletions packages/form/src/demos/components-other-readonly.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ const Demo = () => (
transform={(value: any) => ({ startTime: value[0], endTime: value[1] })}
>
<ProFormText width="m" readonly />
-
<ProFormText width="m" readonly />
-
<ProFormText width="m" readonly />
</ProFromFieldSet>
<ProForm.Group title="日期相关分组">
Expand Down
12 changes: 12 additions & 0 deletions tests/form/__snapshots__/demo.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3967,12 +3967,24 @@ exports[`form demos renders ./packages/form/src/demos/components-other-readonly.
>
1
</div>
<div
class="ant-space-item"
style="margin-right: 8px;"
>
-
</div>
<div
class="ant-space-item"
style="margin-right: 8px;"
>
2
</div>
<div
class="ant-space-item"
style="margin-right: 8px;"
>
-
</div>
<div
class="ant-space-item"
>
Expand Down

0 comments on commit aa40d77

Please sign in to comment.