mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
fix(components): [tree] dragging a node will deselect the node (#14830)
* fix(components): [tree] Dragging a node will deselect the node(#13912) * fix(components): [tree] Dragging a node will deselect the node (#13912) * fix(components): [tree] Dragging a node will deselect the node (#13912) The Node class adds a method to set the checked state, which only affects the parent node state. * refactor: optimized code * fix(components): [tree] Dragging a node will deselect the node (#13912) checkStrictly is true no need reInitCheckek * fix(components): [tree] Dragging a node will deselect the node (#13912)
This commit is contained in:
@@ -558,6 +558,20 @@ class Node {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
eachNode(callback: (node: Node) => void) {
|
||||
const arr: Node[] = [this]
|
||||
while (arr.length) {
|
||||
const node = arr.shift()!
|
||||
arr.unshift(...node.childNodes)
|
||||
callback(node)
|
||||
}
|
||||
}
|
||||
|
||||
reInitChecked() {
|
||||
if (this.store.checkStrictly) return
|
||||
reInitChecked(this)
|
||||
}
|
||||
}
|
||||
|
||||
export default Node
|
||||
|
||||
@@ -180,6 +180,15 @@ export function useDragNodeHandler({ props, ctx, el$, dropIndicator$, store }) {
|
||||
}
|
||||
if (dropType !== 'none') {
|
||||
store.value.registerNode(draggingNodeCopy)
|
||||
if (store.value.key) {
|
||||
//restore checkbox state after dragging
|
||||
draggingNode.node.eachNode((node) => {
|
||||
store.value.nodesMap[node.data[store.value.key]]?.setChecked(
|
||||
node.checked,
|
||||
!store.value.checkStrictly
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
removeClass(dropNode.$el, ns.is('drop-inner'))
|
||||
|
||||
@@ -183,6 +183,11 @@ export default defineComponent({
|
||||
}
|
||||
)
|
||||
|
||||
watch(
|
||||
() => props.node.childNodes.length,
|
||||
() => props.node.reInitChecked()
|
||||
)
|
||||
|
||||
watch(
|
||||
() => props.node.expanded,
|
||||
(val) => {
|
||||
|
||||
Reference in New Issue
Block a user