Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(check-cascader): 修复checkedMode="PARENT"模式下搜索后子节点无法勾选的问题 #2993

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/breezy-berries-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/check-cascader": patch
---

fix: 优化搜索算法
5 changes: 5 additions & 0 deletions .changeset/grumpy-tips-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/check-cascader": patch
---

fix: 修复 checkedMode="PARENT"模式下搜索后子节点无法选中问题
5 changes: 5 additions & 0 deletions .changeset/lovely-suns-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/hiui": patch
---

fix(check-cascader): 优化搜索算法
5 changes: 5 additions & 0 deletions .changeset/silver-bulldogs-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/hiui": patch
---

fix(check-cascader): 修复 checkedMode="PARENT"模式下搜索后子节点无法选中问题
1 change: 1 addition & 0 deletions packages/ui/check-cascader/src/CheckCascader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ export const CheckCascader = forwardRef<HTMLDivElement | null, CheckCascaderProp
flatted={flatted || !!searchValue}
// @ts-ignore
flattedData={selectProps.data}
originalFlattedData={flattedData}
data={cascaderData}
onChangeData={setCascaderData}
checkedMode={checkedMode}
Expand Down
8 changes: 7 additions & 1 deletion packages/ui/check-cascader/src/CheckCascaderMenuList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const CheckCascaderMenuList = forwardRef<HTMLDivElement | null, CascaderM
children,
data,
flattedData,
originalFlattedData,
onChangeData,
value: valueProp,
defaultValue = NOOP_ARRAY,
Expand Down Expand Up @@ -59,7 +60,7 @@ export const CheckCascaderMenuList = forwardRef<HTMLDivElement | null, CascaderM
const [onOptionCheck, isCheckedId, isSemiCheckedId] = useCheck(
checkedMode,
disabled,
flattedData,
originalFlattedData,
defaultValue,
valueProp,
({ checkedIds, semiCheckedIds }, target, shouldChecked) => {
Expand Down Expand Up @@ -164,6 +165,11 @@ export interface CascaderMenusProps {
* 设置选择项数据源
*/
flattedData: FlattedCheckCascaderDataItem[]
/**
* 未被过滤的选择项数据源,Hotfix:https://github.com/XiaoMi/hiui/issues/2992
* @private
*/
originalFlattedData: FlattedCheckCascaderDataItem[]
/**
* 设置当前多选值
*/
Expand Down
6 changes: 4 additions & 2 deletions packages/ui/check-cascader/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,12 @@ export const processCheckedIds = (
allowCheck: (node: any) => boolean
) => {
const keySet = new Set(checkedIds)
const flattenDataMap = new Map(flattenData.map((node: any) => [node.id, node]))

switch (type) {
case 'CHILD':
return checkedIds.filter((id) => {
const node = fFindNodeById(flattenData, id)
const node = flattenDataMap.get(id) as any

if (node) {
const { children } = node
Expand All @@ -144,7 +145,8 @@ export const processCheckedIds = (

case 'PARENT':
return checkedIds.filter((id) => {
const node = fFindNodeById(flattenData, id) as any
const node = flattenDataMap.get(id) as any

if (node) {
// 向上递归遍历是否被勾选
const ancestors = getNodeAncestors(node)
Expand Down