Skip to content

[pull] main from arco-design:main #69

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

Merged
merged 3 commits into from
Aug 6, 2025
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
8 changes: 8 additions & 0 deletions components/Cascader/__changelog__/index.en-US.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 2.66.3

2025-08-06

### 🐛 BugFix

- Fixed a bug in the `Cascader` component where the `isLeaf` node selection check would fail after `loadMore` was enabled.([#3033](https://github.com/arco-design/arco-design/pull/3033))

## 2.66.0

2025-04-03
Expand Down
8 changes: 8 additions & 0 deletions components/Cascader/__changelog__/index.zh-CN.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 2.66.3

2025-08-06

### 🐛 问题修复

- 修复 `Cascader` 组件在开启 `loadMore` 之后,对 `isLeaf` 节点选中判断有问题的 bug。([#3033](https://github.com/arco-design/arco-design/pull/3033))

## 2.66.0

2025-04-03
Expand Down
32 changes: 31 additions & 1 deletion components/Cascader/base/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ class Node<T> {
* 那么只有当前节点的所有children加起来等于children.length,才是全选,否则和大于0,就是半选。
*/
private _isHalfChecked = () => {
if (!this.children || this.children.length === 0) {
return false;
}

const checkedLen = this.children.reduce((total, prev) => {
const num = prev._halfChecked ? 0.5 : prev._checked ? 1 : 0;
return total + num;
Expand Down Expand Up @@ -184,11 +188,37 @@ class Node<T> {

public updateHalfState = (checked: boolean) => {
this._halfChecked = this._isHalfChecked();
this._checked = this._halfChecked ? false : checked;

if (this._halfChecked) {
// 如果是半选状态,_checked 应该为 false
this._checked = false;
} else if (this.children && this.children.length > 0) {
// 有子节点的情况:检查是否所有子节点都被选中
const allChildrenChecked = this.children.every((child) => child._checked);
this._checked = allChildrenChecked;
} else if (checked && this.config.lazyload && !this.config.changeOnSelect) {
// 没有子节点的情况:使用传入的 checked 值,但需要检查是否为真正的叶子节点
const isActualLeaf =
this.isLeaf || (this.loaded && (!this.children || this.children.length === 0));
this._checked = isActualLeaf ? checked : false;
} else {
// 没有子节点且非 loadMore 模式的情况
this._checked = checked;
}
};

// 直接设置选中状态
public setCheckedProperty = (checked: boolean) => {
// 在 loadMore 模式下,只有真正的叶子节点才能被选中
if (checked && this.config.lazyload && !this.config.changeOnSelect) {
const isActualLeaf =
this.isLeaf || (this.loaded && (!this.children || this.children.length === 0));
if (!isActualLeaf) {
// 如果不是真正的叶子节点,不允许设置为选中状态
return;
}
}

this._checked = checked;
this._halfChecked = false;
};
Expand Down
17 changes: 15 additions & 2 deletions components/Cascader/base/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,15 @@ class Store<T> {

const traversal = (option: Node<T>) => {
if (!option) return;
if (!leafOnly || option.isLeaf) {
// 在 loadMore 模式下,只有确实是叶子节点的才能被选中
// 即:isLeaf 为 true,或者在懒加载模式下已经加载完成且没有子节点
const isActualLeaf =
option.isLeaf ||
(this.config.lazyload &&
option.loaded &&
(!option.children || option.children.length === 0));

if (!leafOnly || isActualLeaf) {
this.flatNodes.push(option);
}
if (isArray(option.children)) {
Expand Down Expand Up @@ -105,10 +113,15 @@ class Store<T> {
const options = this._calcNodes(children, node);
node.children = options;

// 标记节点已加载完成
node.setLoading(false);

this._updateFlatNodes();
if (this.config.changeOnSelect) {
// node.setCheckedProperty(checked);
} else {
} else if (node._checked && children.length > 0) {
// 在多选模式下,如果节点有了子节点,需要取消其选中状态
// 因为此时它不再是叶子节点
node.setCheckedState(false);
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@arco-design/web-react",
"version": "2.66.2",
"version": "2.66.3",
"description": "Arco Design React UI Library.",
"module": "./es/index.js",
"main": "./lib/index.js",
Expand Down
8 changes: 8 additions & 0 deletions site/docs/version_v2.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
changelog: true
---

## 2.66.3

2025-08-06

### 🐛 BugFix

- Fixed a bug in the `Cascader` component where the `isLeaf` node selection check would fail after `loadMore` was enabled.([#3033](https://github.com/arco-design/arco-design/pull/3033))

## 2.66.2

2025-07-15
Expand Down
8 changes: 8 additions & 0 deletions site/docs/version_v2.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
changelog: true
---

## 2.66.3

2025-08-06

### 🐛 问题修复

- 修复 `Cascader` 组件在开启 `loadMore` 之后,对 `isLeaf` 节点选中判断有问题的 bug。([#3033](https://github.com/arco-design/arco-design/pull/3033))

## 2.66.2

2025-07-15
Expand Down
Loading