From 5d88e29a439c4966dcaa1a83056000a43797323c Mon Sep 17 00:00:00 2001 From: Janry Date: Fri, 30 Jul 2021 20:24:56 +0800 Subject: [PATCH] fix(antd/next/element): fix array base addition default value (#1913) --- packages/antd/src/array-base/index.tsx | 4 ++-- packages/element/src/array-base/index.ts | 4 ++-- packages/next/src/array-base/index.tsx | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/antd/src/array-base/index.tsx b/packages/antd/src/array-base/index.tsx index 9248aef3b1a..e1a978b9b5d 100644 --- a/packages/antd/src/array-base/index.tsx +++ b/packages/antd/src/array-base/index.tsx @@ -11,7 +11,7 @@ import { AntdIconProps } from '@ant-design/icons/lib/components/AntdIcon' import { ButtonProps } from 'antd/lib/button' import { ArrayField } from '@formily/core' import { useField, useFieldSchema, Schema, JSXComponent } from '@formily/react' -import { isValid } from '@formily/shared' +import { isValid, clone } from '@formily/shared' import { SortableHandle } from 'react-sortable-hoc' import { usePrefixCls } from '../__builtins__' import cls from 'classnames' @@ -71,7 +71,7 @@ const useIndex = (index?: number) => { } const getDefaultValue = (defaultValue: any, schema: Schema) => { - if (isValid(defaultValue)) return defaultValue + if (isValid(defaultValue)) return clone(defaultValue) if (Array.isArray(schema?.items)) return getDefaultValue(defaultValue, schema.items[0]) if (schema?.items?.type === 'array') return [] diff --git a/packages/element/src/array-base/index.ts b/packages/element/src/array-base/index.ts index 709afbe79ad..0dc0bf60884 100644 --- a/packages/element/src/array-base/index.ts +++ b/packages/element/src/array-base/index.ts @@ -8,7 +8,7 @@ import { ref, } from '@vue/composition-api' import { Fragment, useField, useFieldSchema, h } from '@formily/vue' -import { isValid, uid } from '@formily/shared' +import { isValid, uid, clone } from '@formily/shared' import { ArrayField } from '@formily/core' import { stylePrefix } from '../__builtins__/configs' @@ -79,7 +79,7 @@ const useKey = () => { } const getDefaultValue = (defaultValue: any, schema: Schema): any => { - if (isValid(defaultValue)) return defaultValue + if (isValid(defaultValue)) return clone(defaultValue) if (Array.isArray(schema?.items)) return getDefaultValue(defaultValue, schema.items[0]) if (schema?.items?.type === 'array') return [] diff --git a/packages/next/src/array-base/index.tsx b/packages/next/src/array-base/index.tsx index 8cbf1db4461..b8802edc2ef 100644 --- a/packages/next/src/array-base/index.tsx +++ b/packages/next/src/array-base/index.tsx @@ -7,7 +7,7 @@ import { PlusOutlined, MenuOutlined, } from '@ant-design/icons' -import { isValid } from '@formily/shared' +import { isValid, clone } from '@formily/shared' import { AntdIconProps } from '@ant-design/icons/lib/components/AntdIcon' import { ButtonProps } from '@alifd/next/lib/button' import { ArrayField } from '@formily/core' @@ -71,7 +71,7 @@ const useIndex = (index?: number) => { } const getDefaultValue = (defaultValue: any, schema: Schema) => { - if (isValid(defaultValue)) return defaultValue + if (isValid(defaultValue)) return clone(defaultValue) if (Array.isArray(schema?.items)) return getDefaultValue(defaultValue, schema.items[0]) if (schema?.items?.type === 'array') return []