Skip to content

Commit

Permalink
Merge pull request #163 from minop1205/fix-162-handle
Browse files Browse the repository at this point in the history
fix: nodes may not be draggable
  • Loading branch information
minop1205 authored Oct 31, 2022
2 parents 65a9a0d + eaf8256 commit b1e3765
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 10 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change Log

## 3.2.2

_Oct 31, 2022_

### Fixed

- Nodes may not be draggable.

## 3.2.1

_Oct 19, 2022_
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@minoru/react-dnd-treeview",
"description": "A draggable / droppable React-based treeview component.",
"version": "3.2.1",
"version": "3.2.2",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
9 changes: 2 additions & 7 deletions src/Node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
useDragNode,
useDropNode,
useDragControl,
useDragHandle,
} from "./hooks";
import { PlaceholderContext } from "./providers";
import { NodeModel, RenderParams } from "./types";
Expand All @@ -36,13 +37,7 @@ export const Node = <T,>(props: Props): ReactElement | null => {
const [isDragging, drag, preview] = useDragNode(item, containerRef);
const [isOver, dragSource, drop] = useDropNode(item, containerRef);

useEffect(() => {
if (handleRef.current) {
drag(handleRef);
} else {
drag(containerRef);
}
}, [handleRef.current]);
useDragHandle(containerRef, handleRef, drag);

if (isDroppable(dragSource?.id, props.id, treeContext)) {
drop(containerRef);
Expand Down
1 change: 1 addition & 0 deletions src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export { useOpenIdsHelper } from "./useOpenIdsHelper";
export { useTreeDragLayer } from "./useTreeDragLayer";
export { useTreeContext } from "./useTreeContext";
export { useContainerClassName } from "./useContainerClassName";
export { useDragHandle } from "./useDragHandle";
22 changes: 22 additions & 0 deletions src/hooks/useDragHandle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useEffect, RefObject } from "react";
import { DragElementWrapper, DragSourceOptions } from "react-dnd";

export const useDragHandle = (
containerRef: RefObject<HTMLElement>,
handleRef: RefObject<any>,
drag: DragElementWrapper<DragSourceOptions>
) => {
if (handleRef.current) {
drag(handleRef);
} else {
drag(containerRef);
}

useEffect(() => {
if (handleRef.current) {
drag(handleRef);
} else {
drag(containerRef);
}
}, [handleRef.current]);
};

0 comments on commit b1e3765

Please sign in to comment.