Skip to content

Commit

Permalink
fix(components): [tree] fix select logic
Browse files Browse the repository at this point in the history
closed #16331
  • Loading branch information
qppq54s committed Apr 2, 2024
1 parent ef5e1b5 commit ef5c3e5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
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

1 comment on commit ef5c3e5

@warmthsea
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.