Skip to content

fix(cascader): incorrect checked behavior when childNode is disabled #2131

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

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
21 changes: 16 additions & 5 deletions js/tree/tree-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,11 @@
if (!tree.nodeMap.get(value)) return false;
// 节点不可选,视为未选中
if (!this.isCheckable()) return false;
// 禁用节点保持原有选中状态
if (this.isDisabledState()) {
const checkedMap = map || tree.checkedMap;
return !!checkedMap.get(value);
}
const checkedMap = map || tree.checkedMap;
// 严格模式,则已经可以判定选中状态
if (checkStrictly) {
Expand All @@ -882,11 +887,17 @@
}
// 如果 valueMode 为 onlyLeaf 并且当前节点是父节点,则进一步判断
if (Array.isArray(children) && children.length > 0) {
// 子节点全部选中,则当前节点选中
checked = children.every((node) => {
const childIsChecked = node.isChecked(checkedMap);
return childIsChecked;
});
// 子节点全部选中(排除禁用节点),则当前节点选中
const enabledChildren = children.filter(node => !node.isDisabled());
if (enabledChildren.length > 0) {
checked = enabledChildren.every((node) => {
const childIsChecked = node.isChecked(checkedMap);
return childIsChecked;

Check failure on line 895 in js/tree/tree-node.ts

View workflow job for this annotation

GitHub Actions / test

Expected parentheses around arrow function argument
});
} else {
// 如果所有子节点都被禁用,则视为未选中
checked = false;
}
} else {
// 从父节点状态推断子节点状态
// 这里再调用 isChecked 会导致死循环
Expand Down
Loading