Skip to content

Commit

Permalink
fixes issue where dragend over document body was not being prevented …
Browse files Browse the repository at this point in the history
…properly
  • Loading branch information
sashamilenkovic committed Sep 5, 2024
1 parent c7b20cb commit c012d3e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
18 changes: 14 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ export function dragAndDrop<T>({

tearDown(parent);

document.addEventListener("dragover", (e) => {
e.preventDefault();
});

const parentData: ParentData<T> = {
getValues,
setValues,
Expand Down Expand Up @@ -545,9 +549,6 @@ function setup<T>(parent: HTMLElement, parentData: ParentData<T>): void {

parent.nestedParent = e.detail.parent;
},
dragStarted: () => {
console.log("YAYAYAYAY");
},
});
}

Expand Down Expand Up @@ -934,10 +935,17 @@ export function dragstart<T>(data: NodeDragEventData<T>) {
return;
}

const config = data.targetData.parent.data.config;
const scrollParent = getScrollables();

console.log(scrollParent);
const dragState = initDrag(data);

//dragState.scrollParentAbortController = addEvents(scrollParent, {
// scroll: preventSortOnScroll(),
//});

const config = data.targetData.parent.data.config;

const originalZIndex = data.targetData.node.el.style.zIndex;

dragState.originalZIndex = originalZIndex;
Expand Down Expand Up @@ -976,6 +984,8 @@ export function handlePointeroverNode<T>(e: PointeroverNodeEvent<T>) {
export function handleEnd<T>(eventData: NodeEventData<T>) {
if (!state) return;

eventData.e.preventDefault();

end(eventData, state);

resetState();
Expand Down
7 changes: 4 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ function isScrollable(element) {
* @internal
*/
export function getScrollables<T>(
data: ParentData<T>
data: ParentData<T>,
withRoot = false
): [HTMLElement, AbortController] {
// Get all potentially scrollable elements
const scrollableElements = document.querySelectorAll("*");
Expand All @@ -177,11 +178,11 @@ export function getScrollables<T>(
return isScrollable(element);
});

nonChildScrollableElements.push(data.config.root);
//nonChildScrollableElements.push(data.config.root);

console.log(nonChildScrollableElements);

return [];
return nonChildScrollableElements as [HTMLElement, AbortController];
}
/**
* Used for setting a single event listener on x number of events for a given
Expand Down
8 changes: 6 additions & 2 deletions tests/pages/scroll/native-drag/vertical.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ const fruits = [
"Avocado",
];
const [parent, values] = useDragAndDrop(fruits);
const [parent, values] = useDragAndDrop(fruits, {
group: "fruits",
});
const vegetables = [
"Carrot",
Expand All @@ -49,7 +51,9 @@ const vegetables = [
"Bell Pepper",
];
const [parent2, values2] = useDragAndDrop(vegetables);
const [parent2, values2] = useDragAndDrop(vegetables, {
group: "fruits",
});
</script>

<template>
Expand Down

0 comments on commit c012d3e

Please sign in to comment.