Skip to content

Commit 87065fe

Browse files
authored
disabledDrop and target/source drop monitoring #62 (#98)
1 parent ec40e35 commit 87065fe

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

packages/react-arborist/src/dnd/drop-hook.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,18 @@ export function useDropHook(
3333
});
3434
if (!drop) return false;
3535
const dropParent = tree.get(drop.parentId) ?? tree.root;
36-
37-
for (let id of item.dragIds) {
38-
const drag = tree.get(id);
36+
37+
const dragNodes = <NodeApi[]>item.dragIds.map(tree.get, tree);
38+
for (const drag of dragNodes) {
3939
if (!drag) return false;
4040
if (!dropParent) return false;
4141
if (drag.isInternal && isDecendent(dropParent, drag)) return false;
4242
}
43+
44+
const check = tree.props.disableDrop;
45+
if (typeof check === 'function' && check(dropParent, dragNodes)) {
46+
return false;
47+
}
4348
return true;
4449
},
4550
hover: (item, m) => {

packages/react-arborist/src/types/tree-props.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export interface TreeProps<T> {
4040
disableMultiSelection?: boolean;
4141
disableEdit?: string | boolean | BoolFunc<T>;
4242
disableDrag?: string | boolean | BoolFunc<T>;
43-
disableDrop?: string | boolean | BoolFunc<T>;
43+
disableDrop?: string | boolean | BoolFunc<T> | ((node: NodeApi, dragNodes: NodeApi[]) => boolean);
4444
childrenAccessor?: string | ((d: T) => T[] | null);
4545
idAccessor?: string | ((d: T) => string);
4646

0 commit comments

Comments
 (0)