Skip to content

Commit

Permalink
Merge pull request #2868 from xiamiao1121/feature/check-cascader/#2866
Browse files Browse the repository at this point in the history
feat(check-cascader): 支持配置字段别名
  • Loading branch information
solarjoker authored Jun 28, 2024
2 parents e9e1a99 + f47509b commit 23ee022
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/grumpy-owls-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/check-cascader": minor
---

feat: 新增支持配置字段别名
5 changes: 5 additions & 0 deletions .changeset/nice-taxis-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/hiui": patch
---

feat(check-cascader): 新增支持配置字段别名
12 changes: 10 additions & 2 deletions packages/ui/check-cascader/src/CheckCascader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { flattenTreeData } from './utils'
import { getNodeAncestorsWithMe, getTopDownAncestors } from '@hi-ui/tree-utils'
import { useLatestCallback } from '@hi-ui/use-latest'
import { isArrayNonEmpty, isFunction, isUndef } from '@hi-ui/type-assertion'
import { HiBaseAppearanceEnum, HiBaseSizeEnum, useLocaleContext } from '@hi-ui/core'
import { HiBaseAppearanceEnum, HiBaseFieldNames, HiBaseSizeEnum, useLocaleContext } from '@hi-ui/core'

import { callAllFuncs } from '@hi-ui/func-utils'

Expand Down Expand Up @@ -72,6 +72,7 @@ export const CheckCascader = forwardRef<HTMLDivElement | null, CheckCascaderProp
size = 'md',
renderExtraFooter,
dropdownColumnRender,
fieldNames,
...rest
},
ref
Expand All @@ -93,7 +94,10 @@ export const CheckCascader = forwardRef<HTMLDivElement | null, CheckCascaderProp

const [cascaderData, setCascaderData] = useCache(data)

const flattedData = useMemo(() => flattenTreeData(cascaderData), [cascaderData])
const flattedData = useMemo(() => flattenTreeData(cascaderData, fieldNames), [
cascaderData,
fieldNames,
])

const [_value, tryChangeValue] = useUncontrolledState(defaultValue, valueProp, onChange)
// 内部实现使用尾部 id
Expand Down Expand Up @@ -280,6 +284,10 @@ export interface CheckCascaderProps extends Omit<PickerProps, 'trigger' | 'scrol
* 设置选择项数据源
*/
data: CheckCascaderDataItem[]
/**
* 设置 data 中字段对应的 key
*/
fieldNames?: HiBaseFieldNames
/**
* 设置当前多选值
*/
Expand Down

0 comments on commit 23ee022

Please sign in to comment.