From e0f10041fe823714e4a32e6068edfeb56d8b9560 Mon Sep 17 00:00:00 2001
From: Ben Honeywill <17055607+benhoneywill@users.noreply.github.com>
Date: Mon, 21 Mar 2022 20:11:48 +0000
Subject: [PATCH] fix the drag and drop overflow scroll (#36)
---
.../components/category-drop-zone.tsx | 101 ++++++++++--------
.../components/draggable-category.tsx | 7 +-
.../components/horizontal-scroller.tsx | 19 ++--
3 files changed, 67 insertions(+), 60 deletions(-)
diff --git a/app/components/drag-and-drop/components/category-drop-zone.tsx b/app/components/drag-and-drop/components/category-drop-zone.tsx
index 8ed6340..92e3ad9 100644
--- a/app/components/drag-and-drop/components/category-drop-zone.tsx
+++ b/app/components/drag-and-drop/components/category-drop-zone.tsx
@@ -2,7 +2,7 @@ import type { FC } from "react";
import { useContext } from "react";
-import { Box } from "@chakra-ui/layout";
+import { Box, HStack } from "@chakra-ui/layout";
import { Droppable } from "react-beautiful-dnd";
import { Button } from "@chakra-ui/button";
import { useColorModeValue } from "@chakra-ui/react";
@@ -22,54 +22,63 @@ const CategoryDropZone: FC = () => {
const dragColor = useColorModeValue("blue.200", "blue.700");
return (
-
- {(provided, snapshot) => (
-
-
- {categories.map((category, index) => (
-
- ))}
+
+
+ {(provided, snapshot) => (
+
+
+ {categories.map((category, index) => (
+
+ ))}
- {provided.placeholder}
+ {provided.placeholder}
- {addCategory && (
-
-
-
- )}
-
-
- )}
-
+
+
+ )}
+
+
+ )}
+
+
);
};
diff --git a/app/components/drag-and-drop/components/draggable-category.tsx b/app/components/drag-and-drop/components/draggable-category.tsx
index a442453..c23d2c5 100644
--- a/app/components/drag-and-drop/components/draggable-category.tsx
+++ b/app/components/drag-and-drop/components/draggable-category.tsx
@@ -20,7 +20,12 @@ const DraggableCategory: FC = memo(
const { readonly } = useContext(dragAndDropContext);
return (
-
+ e.stopPropagation()}
+ >
{
}, [isDown, bgDragEnabled, scrollLeft, startX]);
return (
- {
- if (
- scroller.current &&
- e.target === scroller.current &&
- bgDragEnabled
- ) {
+ if (scroller.current && bgDragEnabled) {
setIsDown(true);
setStartX(e.pageX - scroller.current?.offsetLeft);
setScrollLeft(scroller.current?.scrollLeft);
@@ -94,7 +87,7 @@ const HorizontalScroller: FC = ({ children }) => {
}}
>
{children}
-
+
);
};