Skip to content

Commit 3423db2

Browse files
committed
fix(antd/next): fix cascader preview text exception errors
1 parent 378496b commit 3423db2

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

packages/antd/src/preview-text/index.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { createContext, useContext } from 'react'
2-
import { isArr, isValid } from '@formily/shared'
2+
import { isArr, toArr, isValid } from '@formily/shared'
33
import { Field } from '@formily/core'
44
import { observer, useField } from '@formily/react'
55
import { InputProps } from 'antd/lib/input'
@@ -213,9 +213,10 @@ const Cascader: React.FC<CascaderProps> = observer((props) => {
213213
? props.options
214214
: []
215215
const getSelected = () => {
216+
const val = toArr(props.value)
216217
return props.multiple
217-
? props.value.map((item) => item[item.length - 1])
218-
: props.value.slice(props.value.length - 1)
218+
? val.map((item) => item[item.length - 1])
219+
: val.slice(props.value.length - 1)
219220
}
220221
const getLabels = () => {
221222
const selected = getSelected()

packages/next/src/preview-text/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { createContext, useContext } from 'react'
2-
import { isArr, isEmpty, isValid } from '@formily/shared'
2+
import { isArr, isEmpty, isValid, toArr } from '@formily/shared'
33
import { Field } from '@formily/core'
44
import { useField, observer } from '@formily/react'
55
import { InputProps } from '@alifd/next/lib/input'
@@ -208,7 +208,7 @@ const Cascader: React.FC<CascaderProps> = observer((props) => {
208208
? props.dataSource
209209
: []
210210
const getSelected = () => {
211-
return props.multiple ? props.value : [props.value]
211+
return props.multiple ? toArr(props.value) : [props.value]
212212
}
213213
const getLabels = () => {
214214
const selected = getSelected()

0 commit comments

Comments
 (0)