Skip to content

Commit

Permalink
disabledDrop and target/source drop monitoring #62 (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmeschian authored Jan 26, 2023
1 parent ec40e35 commit 87065fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions packages/react-arborist/src/dnd/drop-hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,18 @@ export function useDropHook(
});
if (!drop) return false;
const dropParent = tree.get(drop.parentId) ?? tree.root;

for (let id of item.dragIds) {
const drag = tree.get(id);
const dragNodes = <NodeApi[]>item.dragIds.map(tree.get, tree);
for (const drag of dragNodes) {
if (!drag) return false;
if (!dropParent) return false;
if (drag.isInternal && isDecendent(dropParent, drag)) return false;
}

const check = tree.props.disableDrop;
if (typeof check === 'function' && check(dropParent, dragNodes)) {
return false;
}
return true;
},
hover: (item, m) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-arborist/src/types/tree-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export interface TreeProps<T> {
disableMultiSelection?: boolean;
disableEdit?: string | boolean | BoolFunc<T>;
disableDrag?: string | boolean | BoolFunc<T>;
disableDrop?: string | boolean | BoolFunc<T>;
disableDrop?: string | boolean | BoolFunc<T> | ((node: NodeApi, dragNodes: NodeApi[]) => boolean);
childrenAccessor?: string | ((d: T) => T[] | null);
idAccessor?: string | ((d: T) => string);

Expand Down

0 comments on commit 87065fe

Please sign in to comment.