From 739e8c180c5c9f42d24bfd4238e08aa4c93c209c Mon Sep 17 00:00:00 2001 From: Grapedge Date: Tue, 3 Aug 2021 11:45:58 +0800 Subject: [PATCH] fix(next/designable-antd): fix Select bug && designable-antd spelling error (#1934) * fix(next): fix Select cannot be selected when children is empty * fix(designable-antd): fix English spelling error --- .../antd/playground/widgets/ActionsWidget.tsx | 2 +- packages/next/src/select/index.tsx | 24 +++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/designable/antd/playground/widgets/ActionsWidget.tsx b/designable/antd/playground/widgets/ActionsWidget.tsx index 760866c24d5..0f517088d30 100644 --- a/designable/antd/playground/widgets/ActionsWidget.tsx +++ b/designable/antd/playground/widgets/ActionsWidget.tsx @@ -11,7 +11,7 @@ export const ActionsWidget = observer(() => ( value={GlobalRegistry.getDesignerLanguage()} optionType="button" options={[ - { label: 'Engligh', value: 'en-us' }, + { label: 'English', value: 'en-us' }, { label: '简体中文', value: 'zh-cn' }, ]} onChange={(e) => { diff --git a/packages/next/src/select/index.tsx b/packages/next/src/select/index.tsx index 54c97b818fa..ffa79394e32 100644 --- a/packages/next/src/select/index.tsx +++ b/packages/next/src/select/index.tsx @@ -1,13 +1,33 @@ import { connect, mapReadPretty, mapProps } from '@formily/react' +import { isVoidField } from '@formily/core' import { Select as NextSelect } from '@alifd/next' import { PreviewText } from '../preview-text' import { mapSize, mapStatus } from '../__builtins__' +const patchDataSource = (dataSource: any = []) => { + const removeEmptyChildren = (data: any) => { + const result = { ...data } + if (!result.children || result.children.length === 0) { + delete result.children + } else { + result.children = result.children.map(removeEmptyChildren) + } + return result + } + return dataSource.map(removeEmptyChildren) +} + export const Select = connect( NextSelect, mapProps( - { - dataSource: true, + (props, field) => { + if (isVoidField(field)) { + return props + } + return { + ...props, + dataSource: patchDataSource(props.dataSource ?? field?.dataSource), + } }, mapSize, mapStatus