activate the draggable feature in desktop size only
This commit is contained in:
@@ -120,18 +120,31 @@
|
|||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
padding: 0.5rem 1rem 1rem 1rem;
|
padding: 0.5rem 1rem 1rem 1rem;
|
||||||
margin-bottom: 0.5rem;
|
margin-bottom: 0.5rem;
|
||||||
cursor: grab;
|
|
||||||
user-select: none;
|
user-select: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.categoriesContainer:active {
|
|
||||||
cursor: grabbing;
|
|
||||||
}
|
|
||||||
|
|
||||||
.categoriesContainer::-webkit-scrollbar {
|
.categoriesContainer::-webkit-scrollbar {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Desktop drag cursor */
|
||||||
|
@media (min-width: 1025px) {
|
||||||
|
.categoriesContainer {
|
||||||
|
cursor: grab;
|
||||||
|
}
|
||||||
|
|
||||||
|
.categoriesContainer:active {
|
||||||
|
cursor: grabbing;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Mobile/Tablet - use default cursor */
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
.categoriesContainer {
|
||||||
|
cursor: default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Smooth scrolling for drag interactions */
|
/* Smooth scrolling for drag interactions */
|
||||||
.categoriesContainer.dragging {
|
.categoriesContainer.dragging {
|
||||||
scroll-behavior: auto;
|
scroll-behavior: auto;
|
||||||
@@ -170,6 +183,11 @@
|
|||||||
flex-wrap: nowrap;
|
flex-wrap: nowrap;
|
||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
cursor: grab;
|
||||||
|
}
|
||||||
|
|
||||||
|
.categoriesContainer:active {
|
||||||
|
cursor: grabbing;
|
||||||
}
|
}
|
||||||
|
|
||||||
.categoriesSticky {
|
.categoriesSticky {
|
||||||
|
|||||||
@@ -26,11 +26,14 @@ export function CategoriesList({ categories }: CategoriesListProps) {
|
|||||||
} = useScrollHandler();
|
} = useScrollHandler();
|
||||||
const { isRTL } = useAppSelector((state) => state.locale);
|
const { isRTL } = useAppSelector((state) => state.locale);
|
||||||
|
|
||||||
// Drag scroll functionality
|
// Drag scroll functionality (desktop only)
|
||||||
const isDragging = useRef(false);
|
const isDragging = useRef(false);
|
||||||
const startX = useRef(0);
|
const startX = useRef(0);
|
||||||
const scrollLeft = useRef(0);
|
const scrollLeft = useRef(0);
|
||||||
|
|
||||||
|
// Only enable drag on desktop (not mobile or tablet)
|
||||||
|
const isDesktop = !xs;
|
||||||
|
|
||||||
const getCategoryCardStyle = useCallback(() => {
|
const getCategoryCardStyle = useCallback(() => {
|
||||||
if (xs) {
|
if (xs) {
|
||||||
return {
|
return {
|
||||||
@@ -98,8 +101,11 @@ export function CategoriesList({ categories }: CategoriesListProps) {
|
|||||||
}
|
}
|
||||||
}, [activeCategory, scrollCategoryCardIntoView]);
|
}, [activeCategory, scrollCategoryCardIntoView]);
|
||||||
|
|
||||||
// Drag scroll event handlers
|
// Drag scroll event handlers (desktop only)
|
||||||
const handleMouseDown = useCallback((e: React.MouseEvent) => {
|
const handleMouseDown = useCallback(
|
||||||
|
(e: React.MouseEvent) => {
|
||||||
|
if (!isDesktop) return;
|
||||||
|
|
||||||
const container = categoriesContainerRef?.current;
|
const container = categoriesContainerRef?.current;
|
||||||
if (!container) return;
|
if (!container) return;
|
||||||
|
|
||||||
@@ -109,9 +115,15 @@ export function CategoriesList({ categories }: CategoriesListProps) {
|
|||||||
|
|
||||||
// Prevent text selection during drag
|
// Prevent text selection during drag
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}, [categoriesContainerRef]);
|
},
|
||||||
|
[categoriesContainerRef, isDesktop],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleMouseMove = useCallback(
|
||||||
|
(e: React.MouseEvent) => {
|
||||||
|
// Only enable drag on desktop
|
||||||
|
if (!isDesktop) return;
|
||||||
|
|
||||||
const handleMouseMove = useCallback((e: React.MouseEvent) => {
|
|
||||||
const container = categoriesContainerRef?.current;
|
const container = categoriesContainerRef?.current;
|
||||||
if (!container || !isDragging.current) return;
|
if (!container || !isDragging.current) return;
|
||||||
|
|
||||||
@@ -119,7 +131,9 @@ export function CategoriesList({ categories }: CategoriesListProps) {
|
|||||||
const x = e.pageX - container.offsetLeft;
|
const x = e.pageX - container.offsetLeft;
|
||||||
const walk = (x - startX.current) * 2; // Multiply for faster scrolling
|
const walk = (x - startX.current) * 2; // Multiply for faster scrolling
|
||||||
container.scrollLeft = scrollLeft.current - walk;
|
container.scrollLeft = scrollLeft.current - walk;
|
||||||
}, [categoriesContainerRef]);
|
},
|
||||||
|
[categoriesContainerRef, isDesktop],
|
||||||
|
);
|
||||||
|
|
||||||
const handleMouseUp = useCallback(() => {
|
const handleMouseUp = useCallback(() => {
|
||||||
isDragging.current = false;
|
isDragging.current = false;
|
||||||
@@ -129,27 +143,20 @@ export function CategoriesList({ categories }: CategoriesListProps) {
|
|||||||
isDragging.current = false;
|
isDragging.current = false;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Touch event handlers for mobile
|
// Touch event handlers - disabled for mobile/tablet (use native scroll)
|
||||||
const handleTouchStart = useCallback((e: React.TouchEvent) => {
|
const handleTouchStart = useCallback(() => {
|
||||||
const container = categoriesContainerRef?.current;
|
// Disable custom touch handling - let native scroll work
|
||||||
if (!container) return;
|
return;
|
||||||
|
}, []);
|
||||||
|
|
||||||
isDragging.current = true;
|
const handleTouchMove = useCallback(() => {
|
||||||
startX.current = e.touches[0].pageX - container.offsetLeft;
|
// Disable custom touch handling - let native scroll work
|
||||||
scrollLeft.current = container.scrollLeft;
|
return;
|
||||||
}, [categoriesContainerRef]);
|
}, []);
|
||||||
|
|
||||||
const handleTouchMove = useCallback((e: React.TouchEvent) => {
|
|
||||||
const container = categoriesContainerRef?.current;
|
|
||||||
if (!container || !isDragging.current) return;
|
|
||||||
|
|
||||||
const x = e.touches[0].pageX - container.offsetLeft;
|
|
||||||
const walk = (x - startX.current) * 2;
|
|
||||||
container.scrollLeft = scrollLeft.current - walk;
|
|
||||||
}, [categoriesContainerRef]);
|
|
||||||
|
|
||||||
const handleTouchEnd = useCallback(() => {
|
const handleTouchEnd = useCallback(() => {
|
||||||
isDragging.current = false;
|
// Disable custom touch handling - let native scroll work
|
||||||
|
return;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user