-
-
Notifications
You must be signed in to change notification settings - Fork 652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: improve drag behaviour when using handle #2407
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
@@ -74,6 +74,9 @@ const addEventListeners = ( | |||
|
|||
handleEl.addEventListener('mouseenter', onMouseEnter); | |||
handleEl.addEventListener('mouseleave', onMouseLeave); | |||
if (handle) { | |||
el.addEventListener('mouseenter', onMouseLeave); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: should line 75 be on the else statement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I don't think it should, but I'm curious about your reasoning. We want onMouseEnter
on handleEl
every time - Whenever the mouse enters the element that will act as our handle, whether that's a specific "handle" or our whole element, we want it to enable the draggable state:
unleash/frontend/src/hooks/useDragItem.ts
Lines 47 to 51 in d8ffbe2
const onMouseEnter = (e: MouseEvent) => { | |
if (e.target === handleEl) { | |
el.draggable = true; | |
} | |
}; |
What this PR adds, is that whenever we're using the handle
parameter (which means drag only on a specific "handle", not the whole element), we want to reset the draggable state when we enter (or re-enter) the container el
.
So:
- Entering our
handleEl
should enable the draggable state (line 75) - This applies whether we're using a specific "handle" or not; - Entering (or re-entering) the container
el
, our whole element, should reset the state (line 78), but only when using a specific "handle", otherwise it breaks the default behaviour of the whole thing being draggable;
Maybe it's easier to understand if you checkout the branch and try it yourself. To toggle between "drag only on handle" and "everything draggable" you can comment this line:
unleash/frontend/src/component/environments/EnvironmentTable/EnvironmentRow/EnvironmentRow.tsx
Line 33 in d8ffbe2
dragHandleRef |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh! Thanks for the clarification! I didn't realize they were targeting different elements. The names didn't help, but I think it's not easy to give proper names to elements in the UI, it becomes too specific.
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.