Skip to content

Commit

Permalink
Ignore drag events on the children
Browse files Browse the repository at this point in the history
  • Loading branch information
amanmahajan7 committed Sep 12, 2023
1 parent 2aff73a commit ac9007d
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/HeaderCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,17 @@ export default function HeaderCell<R, SR>({
}
}

function handleDragEnter() {
setIsOver(true);
function handleDragEnter(event: React.DragEvent<HTMLDivElement>) {
console.log(event.target);
if (isEventPertinent(event)) {
setIsOver(true);
}
}

function handleDragLeave() {
setIsOver(false);
function handleDragLeave(event: React.DragEvent<HTMLDivElement>) {
if (isEventPertinent(event)) {
setIsOver(false);
}
}

return (
Expand Down Expand Up @@ -275,3 +280,12 @@ export default function HeaderCell<R, SR>({
</div>
);
}

// only accept pertinent drag events:
// - ignore drag events going from the container to an element inside the container
// - ignore drag events going from an element inside the container to the container
function isEventPertinent(event: React.DragEvent) {
const relatedTarget = event.relatedTarget as HTMLElement | null;

return !event.currentTarget.contains(relatedTarget);
}

0 comments on commit ac9007d

Please sign in to comment.