From ee518ff4519e8caeff50272d0d35517980d20a10 Mon Sep 17 00:00:00 2001 From: vshnosngh Date: Thu, 5 Nov 2026 13:10:05 +0530 Subject: [PATCH] fix(ui): drag slider only via arrows handle on phones and make whole trendy bento card clickable --- .../sections/ShiftableToolsGridSection.tsx | 119 +++++++----------- .../sections/TrendyBentoSection.tsx | 15 +-- src/components/ui/CardBeforeAfterSlider.tsx | 50 ++++---- src/components/ui/Cinematic3DComparison.tsx | 60 ++++----- tests/slider.test.tsx | 24 +++- 5 files changed, 133 insertions(+), 135 deletions(-) diff --git a/src/components/sections/ShiftableToolsGridSection.tsx b/src/components/sections/ShiftableToolsGridSection.tsx index fe8f3c5..1e219c3 100644 --- a/src/components/sections/ShiftableToolsGridSection.tsx +++ b/src/components/sections/ShiftableToolsGridSection.tsx @@ -184,64 +184,32 @@ function ShiftableRow({ items }: { items: ToolMediaItem[] }) { }} className="w-full transition-[flex-grow] duration-1000 ease-[cubic-bezier(0.16,1,0.3,1)] will-change-[flex-grow] flex flex-col min-w-0" > - {/* Window Container with strictly locked pixel height & landscape aspect */} - {item.mediaType === 'comparison' ? ( -
- {/* GPU-Composited Shadow Elevation Layer */} - diff --git a/src/components/ui/CardBeforeAfterSlider.tsx b/src/components/ui/CardBeforeAfterSlider.tsx index 5130124..d3ab408 100644 --- a/src/components/ui/CardBeforeAfterSlider.tsx +++ b/src/components/ui/CardBeforeAfterSlider.tsx @@ -73,10 +73,11 @@ export function CardBeforeAfterSlider({ } }, [setSplit]); - // Unified Pointer Handlers (Flawless on iOS/Android touchscreens and desktop mouse) + // Unified Pointer Handlers on Center Pill Handle with Left/Right Arrows const handlePointerDown = useCallback( (e: React.PointerEvent) => { if (e.button !== 0 && e.pointerType === 'mouse') return; + e.stopPropagation(); isDraggingRef.current = true; isInteractedRef.current = true; @@ -88,13 +89,13 @@ export function CardBeforeAfterSlider({ // Fallback } - // Cache rect on pointer down to eliminate layout thrashing - const rect = e.currentTarget.getBoundingClientRect(); - cachedRectRef.current = { left: rect.left, width: rect.width }; - - const x = Math.max(0, Math.min(e.clientX - rect.left, rect.width)); - const percent = (x / rect.width) * 100; - setSplit(percent); + if (containerRef.current) { + const rect = containerRef.current.getBoundingClientRect(); + cachedRectRef.current = { left: rect.left, width: rect.width }; + const x = Math.max(0, Math.min(e.clientX - rect.left, rect.width)); + const percent = (x / rect.width) * 100; + setSplit(percent); + } }, [setSplit] ); @@ -102,6 +103,7 @@ export function CardBeforeAfterSlider({ const handlePointerMove = useCallback( (e: React.PointerEvent) => { if (!isDraggingRef.current) return; + e.stopPropagation(); const clientX = e.clientX; if (rafIdRef.current) { @@ -127,6 +129,7 @@ export function CardBeforeAfterSlider({ const handlePointerUp = useCallback((e: React.PointerEvent) => { if (!isDraggingRef.current) return; + e.stopPropagation(); isDraggingRef.current = false; cachedRectRef.current = null; @@ -147,19 +150,11 @@ export function CardBeforeAfterSlider({ ref={containerRef} onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseLeave} - onPointerDown={handlePointerDown} - onPointerMove={handlePointerMove} - onPointerUp={handlePointerUp} - onPointerCancel={handlePointerUp} - role="slider" - aria-label="Before and after transformation slider" - aria-valuenow={50} - tabIndex={0} style={{ '--split': '50%', - touchAction: 'none', // Strictly prevents mobile touch scrolling interference + touchAction: 'pan-y', // Allows mobile vertical scrolling across the card and line } as React.CSSProperties} - className={`relative w-full ${aspectRatio} overflow-hidden cursor-ew-resize select-none bg-slate-900 group/slider transition-shadow duration-300 hover:shadow-cream-lg touch-none`} + className={`relative w-full ${aspectRatio} overflow-hidden select-none bg-slate-900 group/slider transition-shadow duration-300 hover:shadow-cream-lg`} > {/* Layer 1: After Image (Transformed Neural Result) */} {/* eslint-disable-next-line @next/next/no-img-element */} @@ -186,7 +181,7 @@ export function CardBeforeAfterSlider({ />
- {/* Layer 3: Vertical Split Divider Line */} + {/* Layer 3: Vertical Split Divider Line (pointer-events-none so it doesn't block scrolling) */}
- {/* Center Pill Handle with Left/Right Arrows & Touch Pad */} -
- + {/* Center Pill Handle with Left/Right Arrows - Dedicated Drag Trigger with Pointer Capture */} +
+
diff --git a/src/components/ui/Cinematic3DComparison.tsx b/src/components/ui/Cinematic3DComparison.tsx index f3a0ac8..cb1a6fb 100644 --- a/src/components/ui/Cinematic3DComparison.tsx +++ b/src/components/ui/Cinematic3DComparison.tsx @@ -82,32 +82,32 @@ export function Cinematic3DComparison({ }; }, [autoSlide, isDragging, updatePosition]); - // Unified Pointer Handlers (Works with mouse on desktop + touches/pens on mobile/iOS/tablets) + // Unified Pointer Handlers on the Slider Arrows Handle const handlePointerDown = (e: React.PointerEvent) => { if (e.button !== 0 && e.pointerType === 'mouse') return; + e.stopPropagation(); isPointerDownRef.current = true; setIsDragging(true); - // Capture pointer so fast drags outside the element bounds never lose tracking try { e.currentTarget.setPointerCapture(e.pointerId); } catch { // Fallback } - // Cache rect on pointer down to eliminate layout thrashing during drag - const rect = e.currentTarget.getBoundingClientRect(); - cachedRectRef.current = { left: rect.left, width: rect.width }; - - // Instantly update to pointer position - const x = Math.max(0, Math.min(e.clientX - rect.left, rect.width)); - const percent = (x / rect.width) * 100; - updatePosition(percent); + if (containerRef.current) { + const rect = containerRef.current.getBoundingClientRect(); + cachedRectRef.current = { left: rect.left, width: rect.width }; + const x = Math.max(0, Math.min(e.clientX - rect.left, rect.width)); + const percent = (x / rect.width) * 100; + updatePosition(percent); + } }; const handlePointerMove = (e: React.PointerEvent) => { if (!isPointerDownRef.current) return; + e.stopPropagation(); const clientX = e.clientX; if (rafIdRef.current) { @@ -131,6 +131,7 @@ export function Cinematic3DComparison({ const handlePointerUp = (e: React.PointerEvent) => { if (!isPointerDownRef.current) return; + e.stopPropagation(); isPointerDownRef.current = false; cachedRectRef.current = null; setIsDragging(false); @@ -163,24 +164,13 @@ export function Cinematic3DComparison({ return (
- {/* 3D Kinetic Tilt Stage with Locked Touch-Action for Flawless Mobile Swiping */} + {/* 3D Kinetic Tilt Stage - Allows smooth page scrolling when touching anywhere except the arrows handle */}
{/* Layer 1: After Image (Full Reconstructed Neural Result) */} @@ -208,7 +198,7 @@ export function Cinematic3DComparison({ />
- {/* Layer 3: Illuminated Holographic Laser Split Line */} + {/* Layer 3: Illuminated Holographic Laser Split Line (pointer-events-none so it doesn't block scrolling) */}
- {/* 3D Tactile Center Control Handle with generous touch-target area */} + {/* 3D Tactile Center Control Handle with Arrows - Dedicated Drag Trigger with Pointer Capture */}
{/* Outer Metallic Ring */}
diff --git a/tests/slider.test.tsx b/tests/slider.test.tsx index 15d2a91..21794f7 100644 --- a/tests/slider.test.tsx +++ b/tests/slider.test.tsx @@ -4,9 +4,10 @@ import { renderToString } from 'react-dom/server'; import { Cinematic3DComparison } from '@/components/ui/Cinematic3DComparison'; import { CardBeforeAfterSlider } from '@/components/ui/CardBeforeAfterSlider'; import { ShiftableToolsGridSection } from '@/components/sections/ShiftableToolsGridSection'; +import { TrendyBentoSection } from '@/components/sections/TrendyBentoSection'; describe('Before/After Comparison Sliders (Mobile & Touch Responsiveness)', () => { - it('Cinematic3DComparison renders with touch-none, role="slider", and touchAction: none', () => { + it('Cinematic3DComparison arrow handle has touch-none, role="slider", and touchAction: none', () => { const html = renderToString( { + it('CardBeforeAfterSlider arrow handle has touch-none, role="slider", and touchAction: none', () => { const html = renderToString( { + it('ShiftableToolsGridSection renders comparison cards as clickable links with handle-only slider dragging', () => { const html = renderToString( ); @@ -46,6 +49,17 @@ describe('Before/After Comparison Sliders (Mobile & Touch Responsiveness)', () = expect(html).toContain('aria-label="Before and after comparison slider"'); expect(html).toContain('touch-none'); expect(html).toContain('touch-action:none'); - expect(html).toContain('TRY TOOL'); + expect(html).toContain('touch-action:pan-y'); + expect(html).toContain('href="/tools/blemish-remover"'); + }); + + it('TrendyBentoSection renders each tile as a fully clickable card link', () => { + const html = renderToString( + + ); + + expect(html).toContain('href="/tools/background-remover"'); + expect(html).toContain('href="/tools/old-photo-restorer"'); + expect(html).toContain('href="/tools/cartoon-avatar"'); }); });