Skip to content

Commit

Permalink
fix: Clear partial status of previous radio select parents
Browse files Browse the repository at this point in the history
  • Loading branch information
miruskin committed May 11, 2020
1 parent ac461d4 commit 5a655db
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/tree-manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,22 @@ class TreeManager {

// if id is same as previously selected node, then do nothing (since it's state is already set correctly by setNodeCheckedState)
// but if they ar not same, then toggle the previous one
if (prevChecked && prevChecked !== id) this.getNodeById(prevChecked).checked = false
if (prevChecked && prevChecked !== id) {
const prevNode = this.getNodeById(prevChecked)
prevNode.checked = false
// if radioSelect, then we need to remove the partial state from parents of previous node
if (this.radioSelect && this.showPartialState) this.partialCheckParents(prevNode)
}

this.currentChecked = checked ? id : null
}

setNodeCheckedState(id, checked) {
// radioSelect must be done before setting node checked, to avoid conflicts with partialCheckParents
// this only occurs when selecting the parent of a previously selected child when the parent also has a parent
if (this.radioSelect) {
this.togglePreviousChecked(id, checked)
}
const node = this.getNodeById(id)
node.checked = checked

Expand All @@ -158,7 +168,6 @@ class TreeManager {
if (this.simpleSelect) {
this.togglePreviousChecked(id, checked)
} else if (this.radioSelect) {
this.togglePreviousChecked(id, checked)
if (this.showPartialState) {
this.partialCheckParents(node)
}
Expand Down

0 comments on commit 5a655db

Please sign in to comment.