activate the draggable feature in desktop size only

This commit is contained in:
2025-10-11 21:33:49 +03:00
parent 1cc254063d
commit e5f27d4192
2 changed files with 69 additions and 44 deletions

View File

@@ -120,18 +120,31 @@
gap: 0.5rem;
padding: 0.5rem 1rem 1rem 1rem;
margin-bottom: 0.5rem;
cursor: grab;
user-select: none;
}
.categoriesContainer:active {
cursor: grabbing;
}
.categoriesContainer::-webkit-scrollbar {
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 */
.categoriesContainer.dragging {
scroll-behavior: auto;
@@ -170,6 +183,11 @@
flex-wrap: nowrap;
justify-content: flex-start;
align-items: center;
cursor: grab;
}
.categoriesContainer:active {
cursor: grabbing;
}
.categoriesSticky {

View File

@@ -26,11 +26,14 @@ export function CategoriesList({ categories }: CategoriesListProps) {
} = useScrollHandler();
const { isRTL } = useAppSelector((state) => state.locale);
// Drag scroll functionality
// Drag scroll functionality (desktop only)
const isDragging = useRef(false);
const startX = useRef(0);
const scrollLeft = useRef(0);
// Only enable drag on desktop (not mobile or tablet)
const isDesktop = !xs;
const getCategoryCardStyle = useCallback(() => {
if (xs) {
return {
@@ -98,8 +101,11 @@ export function CategoriesList({ categories }: CategoriesListProps) {
}
}, [activeCategory, scrollCategoryCardIntoView]);
// Drag scroll event handlers
const handleMouseDown = useCallback((e: React.MouseEvent) => {
// Drag scroll event handlers (desktop only)
const handleMouseDown = useCallback(
(e: React.MouseEvent) => {
if (!isDesktop) return;
const container = categoriesContainerRef?.current;
if (!container) return;
@@ -109,9 +115,15 @@ export function CategoriesList({ categories }: CategoriesListProps) {
// Prevent text selection during drag
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;
if (!container || !isDragging.current) return;
@@ -119,7 +131,9 @@ export function CategoriesList({ categories }: CategoriesListProps) {
const x = e.pageX - container.offsetLeft;
const walk = (x - startX.current) * 2; // Multiply for faster scrolling
container.scrollLeft = scrollLeft.current - walk;
}, [categoriesContainerRef]);
},
[categoriesContainerRef, isDesktop],
);
const handleMouseUp = useCallback(() => {
isDragging.current = false;
@@ -129,27 +143,20 @@ export function CategoriesList({ categories }: CategoriesListProps) {
isDragging.current = false;
}, []);
// Touch event handlers for mobile
const handleTouchStart = useCallback((e: React.TouchEvent) => {
const container = categoriesContainerRef?.current;
if (!container) return;
// Touch event handlers - disabled for mobile/tablet (use native scroll)
const handleTouchStart = useCallback(() => {
// Disable custom touch handling - let native scroll work
return;
}, []);
isDragging.current = true;
startX.current = e.touches[0].pageX - container.offsetLeft;
scrollLeft.current = container.scrollLeft;
}, [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 handleTouchMove = useCallback(() => {
// Disable custom touch handling - let native scroll work
return;
}, []);
const handleTouchEnd = useCallback(() => {
isDragging.current = false;
// Disable custom touch handling - let native scroll work
return;
}, []);
return (