From bd686eb246b50d38b53259a9cc434bd99512d525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20G=C3=B3is?= Date: Mon, 14 Nov 2022 08:25:20 +0000 Subject: [PATCH] fix: improve drag behaviour when using handle (#2407) Fixes a small bug that caused the item to be draggable when clicking outside of the handle, when using a handle. Basically resets the draggable state when (re)entering the container. --- frontend/src/hooks/useDragItem.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/frontend/src/hooks/useDragItem.ts b/frontend/src/hooks/useDragItem.ts index f94c859410..6dd0f0e517 100644 --- a/frontend/src/hooks/useDragItem.ts +++ b/frontend/src/hooks/useDragItem.ts @@ -74,6 +74,9 @@ const addEventListeners = ( handleEl.addEventListener('mouseenter', onMouseEnter); handleEl.addEventListener('mouseleave', onMouseLeave); + if (handle) { + el.addEventListener('mouseenter', onMouseLeave); + } el.addEventListener('dragstart', onDragStart); el.addEventListener('dragenter', onDragEnter); el.addEventListener('dragover', onDragOver); @@ -82,6 +85,9 @@ const addEventListeners = ( return () => { handleEl.removeEventListener('mouseenter', onMouseEnter); handleEl.removeEventListener('mouseleave', onMouseLeave); + if (handle) { + el.removeEventListener('mouseenter', onMouseLeave); + } el.removeEventListener('dragstart', onDragStart); el.removeEventListener('dragenter', onDragEnter); el.removeEventListener('dragover', onDragOver);