refactor: simplify drag-to-scroll logic to enable dragging on any non-interactive element within the container (fixes my oopsie) (#328)
This commit is contained in:
@@ -81,20 +81,8 @@ export function useDragToScroll({
|
|||||||
// Don't start dragging if clicking on interactive elements
|
// Don't start dragging if clicking on interactive elements
|
||||||
if (isInteractiveElement) return;
|
if (isInteractiveElement) return;
|
||||||
|
|
||||||
// Check if clicking directly on the container (background)
|
// Enable drag-to-scroll for any non-interactive element within the container
|
||||||
const isContainer = target === container;
|
if (container.contains(target)) {
|
||||||
|
|
||||||
// Check if clicking on a spacer div (empty space between lists)
|
|
||||||
// Spacer divs are direct children with minimal/no content
|
|
||||||
const isDirectChild = container.contains(target) && target.parentElement === container;
|
|
||||||
const isSpacer =
|
|
||||||
isDirectChild &&
|
|
||||||
target.textContent?.trim() === "" &&
|
|
||||||
target.children.length === 0 &&
|
|
||||||
!target.closest("[data-rbd-droppable-id]");
|
|
||||||
|
|
||||||
// Allow dragging if clicking on the container background or spacer elements
|
|
||||||
if (isContainer || isSpacer) {
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setIsDragging(true);
|
setIsDragging(true);
|
||||||
startPosRef.current = { x: e.clientX, y: e.clientY };
|
startPosRef.current = { x: e.clientX, y: e.clientY };
|
||||||
|
|||||||
Reference in New Issue
Block a user