From 8c8ae6be4280c9a41f30bcbf8e78c2913d023134 Mon Sep 17 00:00:00 2001 From: Michael Freno Date: Sun, 4 Jan 2026 21:07:37 -0500 Subject: [PATCH] improve mobile ux --- src/components/CustomScrollbar.tsx | 61 +++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/src/components/CustomScrollbar.tsx b/src/components/CustomScrollbar.tsx index 6a6a356..5f09b3d 100644 --- a/src/components/CustomScrollbar.tsx +++ b/src/components/CustomScrollbar.tsx @@ -100,6 +100,43 @@ export default function CustomScrollbar(props: CustomScrollbarProps) { document.addEventListener("mouseup", handleMouseUp); }; + const handleThumbTouchStart = (e: TouchEvent) => { + e.preventDefault(); + e.stopPropagation(); + setIsDragging(true); + + const startY = e.touches[0].clientY; + const startScrollPercentage = scrollPercentage(); + + const handleTouchMove = (moveEvent: TouchEvent) => { + if (!containerRef || !scrollbarRef) return; + + const deltaY = moveEvent.touches[0].clientY - startY; + const trackHeight = scrollbarRef.getBoundingClientRect().height || 0; + const deltaPercentage = (deltaY / trackHeight) * 100; + const newPercentage = Math.max( + 0, + Math.min(100, startScrollPercentage + deltaPercentage) + ); + + const scrollHeight = containerRef.scrollHeight; + const clientHeight = containerRef.clientHeight; + const maxScroll = scrollHeight - clientHeight; + + const targetScroll = (newPercentage / 100) * maxScroll; + containerRef.scrollTop = targetScroll; + }; + + const handleTouchEnd = () => { + setIsDragging(false); + document.removeEventListener("touchmove", handleTouchMove); + document.removeEventListener("touchend", handleTouchEnd); + }; + + document.addEventListener("touchmove", handleTouchMove); + document.addEventListener("touchend", handleTouchEnd); + }; + onMount(() => { if (!containerRef) return; @@ -138,7 +175,8 @@ export default function CustomScrollbar(props: CustomScrollbarProps) { class="relative h-screen w-full overflow-x-hidden overflow-y-auto" style={{ "scrollbar-width": "none", - "-ms-overflow-style": "none" + "-ms-overflow-style": "none", + "touch-action": "pan-y" }} >