From 53842755fff31dad181965586f799d9beda3119e Mon Sep 17 00:00:00 2001 From: zhouyun1 Date: Mon, 9 Sep 2024 10:50:11 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(check-cascader):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/breezy-berries-marry.md | 5 +++++ .changeset/lovely-suns-breathe.md | 5 +++++ packages/ui/check-cascader/src/utils/index.ts | 6 ++++-- 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 .changeset/breezy-berries-marry.md create mode 100644 .changeset/lovely-suns-breathe.md diff --git a/.changeset/breezy-berries-marry.md b/.changeset/breezy-berries-marry.md new file mode 100644 index 000000000..e4f0889e8 --- /dev/null +++ b/.changeset/breezy-berries-marry.md @@ -0,0 +1,5 @@ +--- +"@hi-ui/check-cascader": patch +--- + +fix: 优化搜索算法 diff --git a/.changeset/lovely-suns-breathe.md b/.changeset/lovely-suns-breathe.md new file mode 100644 index 000000000..8b1bb9ab7 --- /dev/null +++ b/.changeset/lovely-suns-breathe.md @@ -0,0 +1,5 @@ +--- +"@hi-ui/hiui": patch +--- + +fix(check-cascader): 优化搜索算法 diff --git a/packages/ui/check-cascader/src/utils/index.ts b/packages/ui/check-cascader/src/utils/index.ts index a65799991..671b098ac 100644 --- a/packages/ui/check-cascader/src/utils/index.ts +++ b/packages/ui/check-cascader/src/utils/index.ts @@ -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 @@ -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) From 2f462c42ec0828e847ca8864b4fe1beaf8bfaf71 Mon Sep 17 00:00:00 2001 From: zhouyun1 Date: Wed, 11 Sep 2024 20:51:03 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(check-cascader):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=20checkedMode=3D"PARENT"=E6=A8=A1=E5=BC=8F=E4=B8=8B=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E5=90=8E=E5=AD=90=E8=8A=82=E7=82=B9=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E9=80=89=E4=B8=AD=E9=97=AE=E9=A2=98=20(#2992)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/grumpy-tips-peel.md | 5 +++++ .changeset/silver-bulldogs-provide.md | 5 +++++ packages/ui/check-cascader/src/CheckCascader.tsx | 1 + packages/ui/check-cascader/src/CheckCascaderMenuList.tsx | 8 +++++++- 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 .changeset/grumpy-tips-peel.md create mode 100644 .changeset/silver-bulldogs-provide.md diff --git a/.changeset/grumpy-tips-peel.md b/.changeset/grumpy-tips-peel.md new file mode 100644 index 000000000..5b4361a9d --- /dev/null +++ b/.changeset/grumpy-tips-peel.md @@ -0,0 +1,5 @@ +--- +"@hi-ui/check-cascader": patch +--- + +fix: 修复 checkedMode="PARENT"模式下搜索后子节点无法选中问题 diff --git a/.changeset/silver-bulldogs-provide.md b/.changeset/silver-bulldogs-provide.md new file mode 100644 index 000000000..a1c6330f3 --- /dev/null +++ b/.changeset/silver-bulldogs-provide.md @@ -0,0 +1,5 @@ +--- +"@hi-ui/hiui": patch +--- + +fix(check-cascader): 修复 checkedMode="PARENT"模式下搜索后子节点无法选中问题 diff --git a/packages/ui/check-cascader/src/CheckCascader.tsx b/packages/ui/check-cascader/src/CheckCascader.tsx index d90cf7e08..6f8acb8a8 100644 --- a/packages/ui/check-cascader/src/CheckCascader.tsx +++ b/packages/ui/check-cascader/src/CheckCascader.tsx @@ -291,6 +291,7 @@ export const CheckCascader = forwardRef { @@ -164,6 +165,11 @@ export interface CascaderMenusProps { * 设置选择项数据源 */ flattedData: FlattedCheckCascaderDataItem[] + /** + * 未被过滤的选择项数据源,Hotfix:https://github.com/XiaoMi/hiui/issues/2992 + * @private + */ + originalFlattedData: FlattedCheckCascaderDataItem[] /** * 设置当前多选值 */