Skip to content

Commit

Permalink
fix(antd/next): fix cascader preview text exception errors (#3000)
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang authored Mar 30, 2022
1 parent 888dc47 commit a48252b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions packages/antd/src/preview-text/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { createContext, useContext } from 'react'
import { isArr, isValid } from '@formily/shared'
import { isArr, toArr, isValid } from '@formily/shared'
import { Field } from '@formily/core'
import { observer, useField } from '@formily/react'
import { InputProps } from 'antd/lib/input'
Expand Down Expand Up @@ -213,9 +213,10 @@ const Cascader: React.FC<CascaderProps> = observer((props) => {
? props.options
: []
const getSelected = () => {
const val = toArr(props.value)
return props.multiple
? props.value.map((item) => item[item.length - 1])
: props.value.slice(props.value.length - 1)
? val.map((item) => item[item.length - 1])
: val.slice(props.value.length - 1)
}
const getLabels = () => {
const selected = getSelected()
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/preview-text/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { createContext, useContext } from 'react'
import { isArr, isEmpty, isValid } from '@formily/shared'
import { isArr, isEmpty, isValid, toArr } from '@formily/shared'
import { Field } from '@formily/core'
import { useField, observer } from '@formily/react'
import { InputProps } from '@alifd/next/lib/input'
Expand Down Expand Up @@ -208,7 +208,7 @@ const Cascader: React.FC<CascaderProps> = observer((props) => {
? props.dataSource
: []
const getSelected = () => {
return props.multiple ? props.value : [props.value]
return props.multiple ? toArr(props.value) : [props.value]
}
const getLabels = () => {
const selected = getSelected()
Expand Down

0 comments on commit a48252b

Please sign in to comment.