Skip to content

Commit

Permalink
adds isOpenWithEmptyChildren to hover.atTop check on computeDrop
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeni Dimov committed Dec 13, 2023
1 parent 7e58836 commit c9af3ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/react-arborist/src/dnd/compute-drop.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { XYCoord } from "react-dnd";
import { NodeApi } from "../interfaces/node-api";
import { bound, indexOf, isClosed, isItem } from "../utils";
import { bound, indexOf, isClosed, isItem, isOpenWithEmptyChildren } from "../utils";
import { DropResult } from "./drop-hook";

function measureHover(el: HTMLElement, offset: XYCoord) {
Expand Down Expand Up @@ -155,7 +155,7 @@ export function computeDrop(args: Args): ComputedDrop {
* The above node is an item, a closed folder or hovering over
* the top of next node, proposing to append as next sibling.
*/
if (isItem(above) || isClosed(above) || hover.atTop) {
if (isItem(above) || isClosed(above) || (!below && hover.inBottomHalf) || (hover.atTop && isOpenWithEmptyChildren(above))) {
const level = getDropLevel(hover, above, below, args.indent);
return {
drop: walkUpFrom(above, level),
Expand Down
4 changes: 4 additions & 0 deletions packages/react-arborist/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export function isClosed(node: NodeApi<any> | null) {
return node && node.isInternal && !node.isOpen;
}

export function isOpenWithEmptyChildren(node: NodeApi<any> | null) {
return node && node.isOpen && !node.children?.length;
}

/**
* Is first param a descendant of the second param
*/
Expand Down

0 comments on commit c9af3ab

Please sign in to comment.