Skip to content

Commit 10091a6

Browse files
committed
fix: get isOutside by coordinates
1 parent e69920a commit 10091a6

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/HeTree.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,15 @@ export function useHeTree<T extends Record<string, any>>(
491491
return
492492
}
493493
// listen dragend. dragend only trigger in dragstart node
494-
const isOutside = !placeholder // placeholder is removed if dragleave the tree
494+
let isOutside = !placeholder // placeholder may be removed if dragleave the tree
495+
if (!isOutside) {
496+
// get isOutside by coordinates
497+
const rootEl = rootRef.current as HTMLElement
498+
let rect = rootEl.getBoundingClientRect()
499+
isOutside = !(e.pageX >= rect.left && e.pageX <= rect.right && e.pageY >= rect.top && e.pageY <= rect.bottom)
500+
}
495501
const customized = props.onDragEnd?.(e, draggingStat!, isOutside) === false
496-
if (!customized && !isOutside) {
502+
if (!customized && placeholder) {
497503
let targetIndexInSiblings = placeholder.index
498504
if (placeholder.parentStat === draggingStat.parentStat && draggingStat.index < targetIndexInSiblings) {
499505
targetIndexInSiblings--

0 commit comments

Comments
 (0)