From 67125bd6045a6ee8f750225780230fcf6ff1e28b Mon Sep 17 00:00:00 2001 From: Janry Date: Tue, 11 Oct 2022 22:58:25 +0800 Subject: [PATCH] fix(next): fix cascader preview text can not shown data (#3447) --- packages/next/src/preview-text/index.tsx | 72 +++++------------------- packages/next/src/preview-text/main.scss | 7 +++ 2 files changed, 21 insertions(+), 58 deletions(-) diff --git a/packages/next/src/preview-text/index.tsx b/packages/next/src/preview-text/index.tsx index 06a0266c4a0..0d211623a1c 100644 --- a/packages/next/src/preview-text/index.tsx +++ b/packages/next/src/preview-text/index.tsx @@ -1,12 +1,12 @@ import React, { createContext, useContext } from 'react' -import { isArr, isEmpty, isValid, toArr } from '@formily/shared' +import { isArr, isEmpty, isValid } from '@formily/shared' import { Field } from '@formily/core' import { useField, observer } from '@formily/react' import { InputProps } from '@alifd/next/lib/input' import { NumberPickerProps } from '@alifd/next/lib/number-picker' import { SelectProps } from '@alifd/next/lib/select' import { TreeSelectProps } from '@alifd/next/lib/tree-select' -import { CascaderProps } from '@alifd/next/lib/cascader' +import { CascaderSelectProps } from '@alifd/next/lib/cascader-select' import { DatePickerProps, RangePickerProps as DateRangePickerProps, @@ -20,6 +20,7 @@ import { Tag, Input as NextInput, NumberPicker as NextNumberPicker, + CascaderSelect as NextCascader, } from '@alifd/next' import cls from 'classnames' import { formatMomentValue, usePrefixCls } from '../__builtins__' @@ -158,64 +159,19 @@ const TreeSelect: React.FC> = observer( } ) -type SelectOptionType = { - value: string - label: string - children?: SelectOptionType[] -} - -const Cascader: React.FC> = observer( - (props) => { +const Cascader: React.FC> = + observer((props) => { const field = useField() - const placeholder = usePlaceholder() const prefixCls = usePrefixCls('form-preview', props) - const dataSource: any[] = field?.dataSource?.length - ? field.dataSource - : props?.dataSource?.length - ? props.dataSource - : [] - const findSelectedItem = ( - items: SelectOptionType[], - val: string | number - ) => { - return items.find((item) => item.value == val) - } - const findSelectedItems = ( - sources: SelectOptionType[], - selectedValues: Array - ): Array => { - return selectedValues.map((value) => { - const result: Array = [] - let items = sources - value.forEach((val) => { - const selectedItem = findSelectedItem(items, val) - result.push({ - label: selectedItem?.label ?? '', - value: selectedItem?.value, - }) - items = selectedItem?.children ?? [] - }) - return result - }) - } - const getSelected = () => { - const val = toArr(props.value) - // unified conversion to multi selection mode - return props.multiple ? val : [val] - } - const getLabels = () => { - const selected = getSelected() - const values = findSelectedItems(dataSource, selected) - const labels = values - .map((val: Array<{ value: string; label: string }>) => { - return val.map((item) => item.label).join('/') - }) - .join(' ') - return labels || placeholder - } - return
{getLabels()}
- } -) + return ( + + ) + }) const DatePicker: React.FC> = ( props diff --git a/packages/next/src/preview-text/main.scss b/packages/next/src/preview-text/main.scss index 94bb41d0b61..bb66f50fd12 100644 --- a/packages/next/src/preview-text/main.scss +++ b/packages/next/src/preview-text/main.scss @@ -5,6 +5,7 @@ $form-preview-prefix-cls: '#{$css-prefix}form-preview'; .#{$form-preview-prefix-cls} { font-weight: 400; word-break: break-all; + .#{$css-prefix}tag { margin-right: 4px; } @@ -13,3 +14,9 @@ $form-preview-prefix-cls: '#{$css-prefix}form-preview'; margin-right: 0; } } + +p.#{$form-preview-prefix-cls} { + margin: 0; + font-size: inherit; + line-height: inherit; +}