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(components): [tree] fix select logic #16362

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 5 additions & 15 deletions packages/components/tree/src/model/node.ts
Expand Up @@ -17,25 +17,21 @@ import type {
export const getChildState = (node: Node[]): TreeNodeChildState => {
let all = true
let none = true
let allWithoutDisable = true
for (let i = 0, j = node.length; i < j; i++) {
const n = node[i]
if (n.checked !== true || n.indeterminate) {
if ((n.checked !== true || n.indeterminate) && !n.disabled) {
all = false
if (!n.disabled) {
allWithoutDisable = false
}
}
if (n.checked !== false || n.indeterminate) {
if ((n.checked !== false || n.indeterminate) && !n.disabled) {
none = false
}
}

return { all, none, allWithoutDisable, half: !all && !none }
return { all, none, half: !all && !none }
}

const reInitChecked = function (node: Node): void {
if (node.childNodes.length === 0 || node.loading) return
if (node.childNodes.length === 0 || node.loading || node.disabled) return

const { all, none, half } = getChildState(node.childNodes)
if (all) {
Expand Down Expand Up @@ -420,18 +416,12 @@ class Node {
if (this.store.checkStrictly) return

if (!(this.shouldLoadData() && !this.store.checkDescendants)) {
const { all, allWithoutDisable } = getChildState(this.childNodes)

if (!this.isLeaf && !all && allWithoutDisable) {
this.checked = false
value = false
}

const handleDescendants = (): void => {
if (deep) {
const childNodes = this.childNodes
for (let i = 0, j = childNodes.length; i < j; i++) {
const child = childNodes[i]
if (child.disabled) continue
passValue = passValue || value !== false
const isCheck = child.disabled ? child.checked : passValue
child.setChecked(isCheck, deep, true, passValue)
Expand Down
2 changes: 1 addition & 1 deletion packages/components/tree/src/model/tree-store.ts
Expand Up @@ -161,7 +161,7 @@ export default class TreeStore {
const node = nodesMap[checkedKey]

if (node) {
node.setChecked(true, !this.checkStrictly)
node.setChecked(true, !this.checkStrictly && !node.disabled)
}
})
}
Expand Down