Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions assets/js/phoenix_live_view/live_socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -683,24 +683,20 @@ export default class LiveSocket {
}
});
this.on("dragleave", (e) => {
const dropzone = closestPhxBinding(
e.target,
this.binding(PHX_DROP_TARGET),
);
const closestDropZone = (el) =>
el instanceof HTMLElement
? closestPhxBinding(el, this.binding(PHX_DROP_TARGET))
: null;

if (!dropzone || !(dropzone instanceof HTMLElement)) {
const dropzone = closestDropZone(e.target) || closestDropZone(e.currentTarget);
if (!dropzone) {
return;
}

// Avoid add/remove jitter in the case that we drag into a new child and that child would
// resolve their closest drop target to the current dropzone element
const rect = dropzone.getBoundingClientRect();
if (
e.clientX <= rect.left ||
e.clientX >= rect.right ||
e.clientY <= rect.top ||
e.clientY >= rect.bottom
) {
const relatedDropzone = closestDropZone(e.relatedTarget);
if (!relatedDropzone) {
this.js().removeClass(dropzone, PHX_DROP_TARGET_ACTIVE_CLASS);
}
});
Expand Down