fix(ui): drag slider only via arrows handle on phones and make whole trendy bento card clickable

This commit is contained in:
2026-11-05 13:10:05 +05:30
parent 3d147dd3de
commit ee518ff451
5 changed files with 133 additions and 135 deletions
@@ -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" 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 */} {/* Window Container with strictly locked pixel height & landscape aspect (entire card is clickable) */}
{item.mediaType === 'comparison' ? ( <Link
<div className="group block relative w-full h-[220px] sm:h-[240px] lg:h-[260px] rounded-2xl sm:rounded-3xl overflow-hidden bg-slate-950 border border-slate-900/[0.08] shadow-cream-sm"> href={`/tools/${item.slug}`}
{/* GPU-Composited Shadow Elevation Layer */} className="group block relative w-full h-[220px] sm:h-[240px] lg:h-[260px] rounded-2xl sm:rounded-3xl overflow-hidden bg-slate-950 border border-slate-900/[0.08] shadow-cream-sm cursor-pointer"
<div >
className="absolute -inset-px rounded-2xl sm:rounded-3xl shadow-cream-lg opacity-0 group-hover:opacity-100 transition-opacity duration-700 ease-[cubic-bezier(0.16,1,0.3,1)] pointer-events-none z-30" {/* GPU-Composited Shadow Elevation Layer */}
aria-hidden="true" <div
/> className="absolute -inset-px rounded-2xl sm:rounded-3xl shadow-cream-lg opacity-0 group-hover:opacity-100 transition-opacity duration-700 ease-[cubic-bezier(0.16,1,0.3,1)] pointer-events-none z-30"
aria-hidden="true"
/>
{/* Media Renderer (Interactive comparison slider with touch-action: none) */} {/* Media Renderer */}
<ToolWindowMedia item={item} isHovered={isHovered} /> <ToolWindowMedia item={item} isHovered={isHovered} />
{/* Dedicated Tool Link Pill on top right so sliding never accidentally navigates */} {/* Hover Media Type Pill */}
<Link <div
href={`/tools/${item.slug}`} className="absolute top-3 left-3 z-20 pointer-events-none opacity-0 group-hover:opacity-100 transition-opacity duration-500 ease-[cubic-bezier(0.16,1,0.3,1)]"
className="absolute top-3 right-3 z-30 inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-[10px] font-mono font-bold tracking-wider uppercase bg-slate-950/85 backdrop-blur-md text-white border border-white/20 hover:bg-blue-600 transition-colors shadow-sm"
aria-label={`Open ${item.title}`}
>
<span>TRY TOOL</span>
<ArrowRight className="w-2.5 h-2.5" />
</Link>
{/* Hover Media Type Pill */}
<div
className="absolute top-3 left-3 z-20 pointer-events-none opacity-0 group-hover:opacity-100 transition-opacity duration-500 ease-[cubic-bezier(0.16,1,0.3,1)]"
>
<span className="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-[10px] font-mono font-bold tracking-wider uppercase bg-slate-950/85 backdrop-blur-md text-white border border-white/20">
<Sliders className="w-3 h-3 text-amber-400" />
<span>comparison</span>
</span>
</div>
</div>
) : (
<Link
href={`/tools/${item.slug}`}
className="group block relative w-full h-[220px] sm:h-[240px] lg:h-[260px] rounded-2xl sm:rounded-3xl overflow-hidden bg-slate-950 border border-slate-900/[0.08] shadow-cream-sm"
> >
{/* GPU-Composited Shadow Elevation Layer (Opacity-only transition, zero paint thrash) */} <span className="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-[10px] font-mono font-bold tracking-wider uppercase bg-slate-950/85 backdrop-blur-md text-white border border-white/20">
<div {item.mediaType === 'video' && <Video className="w-3 h-3 text-cyan-400" />}
className="absolute -inset-px rounded-2xl sm:rounded-3xl shadow-cream-lg opacity-0 group-hover:opacity-100 transition-opacity duration-700 ease-[cubic-bezier(0.16,1,0.3,1)] pointer-events-none z-30" {item.mediaType === 'comparison' && <Sliders className="w-3 h-3 text-amber-400" />}
aria-hidden="true" {item.mediaType === 'photo' && <ImageIcon className="w-3 h-3 text-emerald-400" />}
/> <span>{item.mediaType}</span>
</span>
{/* Media Renderer */} </div>
<ToolWindowMedia item={item} isHovered={isHovered} /> </Link>
{/* Hover Media Type Pill (Smooth GPU Opacity Transition) */}
<div
className="absolute top-3 left-3 z-20 pointer-events-none opacity-0 group-hover:opacity-100 transition-opacity duration-500 ease-[cubic-bezier(0.16,1,0.3,1)]"
>
<span className="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-[10px] font-mono font-bold tracking-wider uppercase bg-slate-950/85 backdrop-blur-md text-white border border-white/20">
{item.mediaType === 'video' && <Video className="w-3 h-3 text-cyan-400" />}
{item.mediaType === 'photo' && <ImageIcon className="w-3 h-3 text-emerald-400" />}
<span>{item.mediaType}</span>
</span>
</div>
</Link>
)}
{/* Little Title Below Window (Fixed height, no vertical jumping) */} {/* Little Title Below Window (Fixed height, no vertical jumping) */}
<Link <Link
@@ -469,21 +437,8 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
return ( return (
<div <div
ref={containerRef} ref={containerRef}
onPointerEnter={handlePointerEnter} style={{ touchAction: 'pan-y' }}
onPointerDown={handlePointerDown} className="relative w-full h-full select-none overflow-hidden bg-slate-950 transform-gpu [backface-visibility:hidden]"
onPointerMove={handlePointerMove}
onPointerUp={handlePointerUp}
onPointerCancel={handlePointerUp}
onPointerLeave={handlePointerLeave}
onKeyDown={handleKeyDown}
role="slider"
aria-label="Before and after comparison slider"
aria-valuemin={8}
aria-valuemax={92}
aria-valuenow={50}
tabIndex={0}
style={{ touchAction: 'none' }}
className="relative w-full h-full select-none cursor-ew-resize overflow-hidden bg-slate-950 transform-gpu [backface-visibility:hidden] touch-none"
> >
{/* BEFORE Image (Base layer, fixed scale & position, 0% zoom) */} {/* BEFORE Image (Base layer, fixed scale & position, 0% zoom) */}
<img <img
@@ -505,14 +460,32 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
loading="lazy" loading="lazy"
/> />
{/* Glowing Slider Divider Line (Direct GPU transform & position) */} {/* Glowing Slider Divider Line (pointer-events-none so touching the line allows page scroll) */}
<div <div
ref={dividerRef} ref={dividerRef}
className="absolute top-0 bottom-0 w-[2.5px] bg-white shadow-[0_0_12px_rgba(255,255,255,1)] pointer-events-none z-10 will-change-transform transform-gpu -translate-x-1/2" className="absolute top-0 bottom-0 w-[2.5px] bg-white shadow-[0_0_12px_rgba(255,255,255,1)] pointer-events-none z-10 will-change-transform transform-gpu -translate-x-1/2"
style={{ left: '50%' }} style={{ left: '50%' }}
> >
{/* Circular Grab Handle with Before/After Arrow Cue & Touch Padding */} {/* Circular Grab Handle with Before/After Arrow Cue & Touch Padding - Dedicated Drag Trigger with Pointer Capture */}
<div className="absolute top-1/2 -translate-y-1/2 -translate-x-1/2 left-1/2 w-8 h-8 rounded-full bg-white shadow-xl border border-slate-200/90 flex items-center justify-center text-xs font-bold text-blue-600 pointer-events-none before:absolute before:-inset-3 before:content-['']"> <div
onPointerDown={handlePointerDown}
onPointerMove={handlePointerMove}
onPointerUp={handlePointerUp}
onPointerCancel={handlePointerUp}
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
}}
onKeyDown={handleKeyDown}
role="slider"
aria-label="Before and after comparison slider"
aria-valuemin={8}
aria-valuemax={92}
aria-valuenow={50}
tabIndex={0}
style={{ touchAction: 'none' }}
className="absolute top-1/2 -translate-y-1/2 -translate-x-1/2 left-1/2 w-8 h-8 rounded-full bg-white shadow-xl border border-slate-200/90 flex items-center justify-center text-xs font-bold text-blue-600 pointer-events-auto cursor-ew-resize touch-none before:absolute before:-inset-3 before:content-['']"
>
↔ ↔
</div> </div>
</div> </div>
@@ -257,9 +257,10 @@ export function TrendyBentoSection({
: 'col-span-1 aspect-square rounded-[36px] sm:rounded-[42px]'; : 'col-span-1 aspect-square rounded-[36px] sm:rounded-[42px]';
return ( return (
<div <Link
key={tile.id} key={tile.id}
className={`group relative flex flex-col justify-between overflow-hidden bg-slate-950 border border-slate-900/[0.08] shadow-cream-sm transition-[transform] duration-500 ease-[cubic-bezier(0.16,1,0.3,1)] hover:-translate-y-1.5 transform-gpu will-change-transform ${tileClasses}`} href={tile.href}
className={`group relative flex flex-col justify-between overflow-hidden bg-slate-950 border border-slate-900/[0.08] shadow-cream-sm transition-[transform] duration-500 ease-[cubic-bezier(0.16,1,0.3,1)] hover:-translate-y-1.5 transform-gpu will-change-transform cursor-pointer ${tileClasses}`}
> >
{/* GPU-composited shadow elevation layer */} {/* GPU-composited shadow elevation layer */}
<div <div
@@ -286,9 +287,10 @@ export function TrendyBentoSection({
{/* Android Quick Settings Size Toggle Button (1x1 to 2x1) */} {/* Android Quick Settings Size Toggle Button (1x1 to 2x1) */}
<button <button
type="button"
onClick={(e) => toggleTileSize(tile.id, e)} onClick={(e) => toggleTileSize(tile.id, e)}
title={tile.isWide ? 'Shrink tile' : 'Expand tile'} title={tile.isWide ? 'Shrink tile' : 'Expand tile'}
className="w-9 h-9 rounded-2xl bg-white/90 hover:bg-white text-slate-800 shadow-md flex items-center justify-center transition-[transform,background-color] duration-200 ease-[cubic-bezier(0.16,1,0.3,1)] hover:scale-110 active:scale-95" className="w-9 h-9 rounded-2xl bg-white/90 hover:bg-white text-slate-800 shadow-md flex items-center justify-center transition-[transform,background-color] duration-200 ease-[cubic-bezier(0.16,1,0.3,1)] hover:scale-110 active:scale-95 z-30"
> >
{tile.isWide ? ( {tile.isWide ? (
<Minimize2 className="w-4 h-4 text-blue-600" /> <Minimize2 className="w-4 h-4 text-blue-600" />
@@ -312,15 +314,14 @@ export function TrendyBentoSection({
{tile.description} {tile.description}
</p> </p>
<Link <div
href={tile.href}
className="mt-2 inline-flex items-center gap-1.5 text-xs font-display font-bold text-cyan-300 group-hover:text-white transition-colors" className="mt-2 inline-flex items-center gap-1.5 text-xs font-display font-bold text-cyan-300 group-hover:text-white transition-colors"
> >
<span>{tile.cta}</span> <span>{tile.cta}</span>
<ArrowRight className="w-3.5 h-3.5 transition-transform group-hover:translate-x-1" /> <ArrowRight className="w-3.5 h-3.5 transition-transform group-hover:translate-x-1" />
</Link> </div>
</div> </div>
</div> </Link>
); );
})} })}
</div> </div>
+28 -22
View File
@@ -73,10 +73,11 @@ export function CardBeforeAfterSlider({
} }
}, [setSplit]); }, [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( const handlePointerDown = useCallback(
(e: React.PointerEvent<HTMLDivElement>) => { (e: React.PointerEvent<HTMLDivElement>) => {
if (e.button !== 0 && e.pointerType === 'mouse') return; if (e.button !== 0 && e.pointerType === 'mouse') return;
e.stopPropagation();
isDraggingRef.current = true; isDraggingRef.current = true;
isInteractedRef.current = true; isInteractedRef.current = true;
@@ -88,13 +89,13 @@ export function CardBeforeAfterSlider({
// Fallback // Fallback
} }
// Cache rect on pointer down to eliminate layout thrashing if (containerRef.current) {
const rect = e.currentTarget.getBoundingClientRect(); const rect = containerRef.current.getBoundingClientRect();
cachedRectRef.current = { left: rect.left, width: rect.width }; cachedRectRef.current = { left: rect.left, width: rect.width };
const x = Math.max(0, Math.min(e.clientX - rect.left, rect.width));
const x = Math.max(0, Math.min(e.clientX - rect.left, rect.width)); const percent = (x / rect.width) * 100;
const percent = (x / rect.width) * 100; setSplit(percent);
setSplit(percent); }
}, },
[setSplit] [setSplit]
); );
@@ -102,6 +103,7 @@ export function CardBeforeAfterSlider({
const handlePointerMove = useCallback( const handlePointerMove = useCallback(
(e: React.PointerEvent<HTMLDivElement>) => { (e: React.PointerEvent<HTMLDivElement>) => {
if (!isDraggingRef.current) return; if (!isDraggingRef.current) return;
e.stopPropagation();
const clientX = e.clientX; const clientX = e.clientX;
if (rafIdRef.current) { if (rafIdRef.current) {
@@ -127,6 +129,7 @@ export function CardBeforeAfterSlider({
const handlePointerUp = useCallback((e: React.PointerEvent<HTMLDivElement>) => { const handlePointerUp = useCallback((e: React.PointerEvent<HTMLDivElement>) => {
if (!isDraggingRef.current) return; if (!isDraggingRef.current) return;
e.stopPropagation();
isDraggingRef.current = false; isDraggingRef.current = false;
cachedRectRef.current = null; cachedRectRef.current = null;
@@ -147,19 +150,11 @@ export function CardBeforeAfterSlider({
ref={containerRef} ref={containerRef}
onMouseEnter={handleMouseEnter} onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave} 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={{ style={{
'--split': '50%', '--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} } 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) */} {/* Layer 1: After Image (Transformed Neural Result) */}
{/* eslint-disable-next-line @next/next/no-img-element */} {/* eslint-disable-next-line @next/next/no-img-element */}
@@ -186,7 +181,7 @@ export function CardBeforeAfterSlider({
/> />
</div> </div>
{/* Layer 3: Vertical Split Divider Line */} {/* Layer 3: Vertical Split Divider Line (pointer-events-none so it doesn't block scrolling) */}
<div <div
className="absolute top-0 bottom-0 w-[2.5px] bg-white z-20 pointer-events-none shadow-[0_0_10px_rgba(0,0,0,0.8)] -translate-x-1/2" className="absolute top-0 bottom-0 w-[2.5px] bg-white z-20 pointer-events-none shadow-[0_0_10px_rgba(0,0,0,0.8)] -translate-x-1/2"
style={{ left: 'var(--split)' }} style={{ left: 'var(--split)' }}
@@ -194,9 +189,20 @@ export function CardBeforeAfterSlider({
{/* Glowing Aura */} {/* Glowing Aura */}
<div className="absolute -top-4 -bottom-4 -left-1.5 w-3.5 bg-gradient-to-r from-blue-500/30 via-white/70 to-amber-400/30 blur-[2px]" /> <div className="absolute -top-4 -bottom-4 -left-1.5 w-3.5 bg-gradient-to-r from-blue-500/30 via-white/70 to-amber-400/30 blur-[2px]" />
{/* Center Pill Handle with Left/Right Arrows & Touch Pad */} {/* Center Pill Handle with Left/Right Arrows - Dedicated Drag Trigger with Pointer Capture */}
<div className="absolute top-1/2 -translate-y-1/2 -translate-x-1/2 w-9 h-9 sm:w-10 sm:h-10 rounded-full bg-white text-slate-800 shadow-xl border border-slate-900/15 flex items-center justify-center transition-transform group-hover/slider:scale-110 before:absolute before:-inset-3 before:content-['']"> <div
<svg className="w-3.5 h-3.5 text-blue-700" fill="none" stroke="currentColor" viewBox="0 0 24 24"> onPointerDown={handlePointerDown}
onPointerMove={handlePointerMove}
onPointerUp={handlePointerUp}
onPointerCancel={handlePointerUp}
role="slider"
aria-label="Before and after transformation slider"
aria-valuenow={50}
tabIndex={0}
style={{ touchAction: 'none' }}
className="absolute top-1/2 -translate-y-1/2 -translate-x-1/2 w-9 h-9 sm:w-10 sm:h-10 rounded-full bg-white text-slate-800 shadow-xl border border-slate-900/15 flex items-center justify-center transition-transform group-hover/slider:scale-110 before:absolute before:-inset-3 before:content-[''] pointer-events-auto cursor-ew-resize touch-none"
>
<svg className="w-3.5 h-3.5 text-blue-700 pointer-events-none" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2.5} d="M8 9l-3 3 3 3m8-6l3 3-3 3" /> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2.5} d="M8 9l-3 3 3 3m8-6l3 3-3 3" />
</svg> </svg>
</div> </div>
+32 -28
View File
@@ -82,32 +82,32 @@ export function Cinematic3DComparison({
}; };
}, [autoSlide, isDragging, updatePosition]); }, [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<HTMLDivElement>) => { const handlePointerDown = (e: React.PointerEvent<HTMLDivElement>) => {
if (e.button !== 0 && e.pointerType === 'mouse') return; if (e.button !== 0 && e.pointerType === 'mouse') return;
e.stopPropagation();
isPointerDownRef.current = true; isPointerDownRef.current = true;
setIsDragging(true); setIsDragging(true);
// Capture pointer so fast drags outside the element bounds never lose tracking
try { try {
e.currentTarget.setPointerCapture(e.pointerId); e.currentTarget.setPointerCapture(e.pointerId);
} catch { } catch {
// Fallback // Fallback
} }
// Cache rect on pointer down to eliminate layout thrashing during drag if (containerRef.current) {
const rect = e.currentTarget.getBoundingClientRect(); const rect = containerRef.current.getBoundingClientRect();
cachedRectRef.current = { left: rect.left, width: rect.width }; cachedRectRef.current = { left: rect.left, width: rect.width };
const x = Math.max(0, Math.min(e.clientX - rect.left, rect.width));
// Instantly update to pointer position const percent = (x / rect.width) * 100;
const x = Math.max(0, Math.min(e.clientX - rect.left, rect.width)); updatePosition(percent);
const percent = (x / rect.width) * 100; }
updatePosition(percent);
}; };
const handlePointerMove = (e: React.PointerEvent<HTMLDivElement>) => { const handlePointerMove = (e: React.PointerEvent<HTMLDivElement>) => {
if (!isPointerDownRef.current) return; if (!isPointerDownRef.current) return;
e.stopPropagation();
const clientX = e.clientX; const clientX = e.clientX;
if (rafIdRef.current) { if (rafIdRef.current) {
@@ -131,6 +131,7 @@ export function Cinematic3DComparison({
const handlePointerUp = (e: React.PointerEvent<HTMLDivElement>) => { const handlePointerUp = (e: React.PointerEvent<HTMLDivElement>) => {
if (!isPointerDownRef.current) return; if (!isPointerDownRef.current) return;
e.stopPropagation();
isPointerDownRef.current = false; isPointerDownRef.current = false;
cachedRectRef.current = null; cachedRectRef.current = null;
setIsDragging(false); setIsDragging(false);
@@ -163,24 +164,13 @@ export function Cinematic3DComparison({
return ( return (
<div className={`w-full perspective-1400 select-none ${className}`}> <div className={`w-full perspective-1400 select-none ${className}`}>
{/* 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 */}
<div <div
ref={containerRef} ref={containerRef}
onPointerDown={handlePointerDown} className={`relative w-full ${aspectRatio} rounded-2xl sm:rounded-3xl overflow-hidden preserve-3d transition-transform duration-150 ease-out shadow-cinematic-3d hover:shadow-cinematic-hover border border-slate-900/[0.08] bg-slate-950`}
onPointerMove={handlePointerMove}
onPointerUp={handlePointerUp}
onPointerCancel={handlePointerUp}
onKeyDown={handleKeyDown}
role="slider"
aria-label="Before and after comparison"
aria-valuemin={0}
aria-valuemax={100}
aria-valuenow={50}
tabIndex={0}
className={`relative w-full ${aspectRatio} rounded-2xl sm:rounded-3xl overflow-hidden cursor-ew-resize preserve-3d transition-transform duration-150 ease-out shadow-cinematic-3d hover:shadow-cinematic-hover border border-slate-900/[0.08] bg-slate-950 touch-none`}
style={{ style={{
'--split': '50%', '--split': '50%',
touchAction: 'none', // Strictly prevents iOS/Android touch scrolling conflict on the slider touchAction: 'pan-y', // Allows mobile vertical scrolling across the image and line
} as React.CSSProperties} } as React.CSSProperties}
> >
{/* Layer 1: After Image (Full Reconstructed Neural Result) */} {/* Layer 1: After Image (Full Reconstructed Neural Result) */}
@@ -208,7 +198,7 @@ export function Cinematic3DComparison({
/> />
</div> </div>
{/* Layer 3: Illuminated Holographic Laser Split Line */} {/* Layer 3: Illuminated Holographic Laser Split Line (pointer-events-none so it doesn't block scrolling) */}
<div <div
className="absolute top-0 bottom-0 w-[2px] bg-gradient-to-b from-blue-400 via-white to-amber-300 z-20 pointer-events-none -translate-x-1/2" className="absolute top-0 bottom-0 w-[2px] bg-gradient-to-b from-blue-400 via-white to-amber-300 z-20 pointer-events-none -translate-x-1/2"
style={{ left: 'var(--split)' }} style={{ left: 'var(--split)' }}
@@ -216,10 +206,24 @@ export function Cinematic3DComparison({
{/* Vertical Caustic Glow Beam */} {/* Vertical Caustic Glow Beam */}
<div className="absolute -top-4 -bottom-4 -left-1.5 w-3.5 bg-gradient-to-r from-blue-500/20 via-white/40 to-amber-400/20 blur-[3px]" /> <div className="absolute -top-4 -bottom-4 -left-1.5 w-3.5 bg-gradient-to-r from-blue-500/20 via-white/40 to-amber-400/20 blur-[3px]" />
{/* 3D Tactile Center Control Handle with generous touch-target area */} {/* 3D Tactile Center Control Handle with Arrows - Dedicated Drag Trigger with Pointer Capture */}
<div <div
className="absolute top-1/2 -translate-y-1/2 -translate-x-1/2 w-10 h-10 sm:w-11 sm:h-11 rounded-full bg-white/95 backdrop-blur-md border border-slate-900/10 shadow-2xl flex items-center justify-center cursor-ew-resize hover:scale-110 active:scale-95 transition-transform duration-150 preserve-3d before:absolute before:-inset-3 before:content-['']" onPointerDown={handlePointerDown}
style={{ transform: 'translateZ(28px)' }} onPointerMove={handlePointerMove}
onPointerUp={handlePointerUp}
onPointerCancel={handlePointerUp}
onKeyDown={handleKeyDown}
role="slider"
aria-label="Before and after comparison slider"
aria-valuemin={0}
aria-valuemax={100}
aria-valuenow={50}
tabIndex={0}
className="absolute top-1/2 -translate-y-1/2 -translate-x-1/2 w-10 h-10 sm:w-11 sm:h-11 rounded-full bg-white/95 backdrop-blur-md border border-slate-900/10 shadow-2xl flex items-center justify-center cursor-ew-resize hover:scale-110 active:scale-95 transition-transform duration-150 preserve-3d before:absolute before:-inset-3 before:content-[''] pointer-events-auto touch-none"
style={{
transform: 'translateZ(28px)',
touchAction: 'none', // Strictly locks drag on the arrow handle only
}}
> >
{/* Outer Metallic Ring */} {/* Outer Metallic Ring */}
<div className="absolute inset-0 rounded-full border border-blue-600/30 shadow-[0_0_12px_rgba(37,99,235,0.3)]" /> <div className="absolute inset-0 rounded-full border border-blue-600/30 shadow-[0_0_12px_rgba(37,99,235,0.3)]" />
+19 -5
View File
@@ -4,9 +4,10 @@ import { renderToString } from 'react-dom/server';
import { Cinematic3DComparison } from '@/components/ui/Cinematic3DComparison'; import { Cinematic3DComparison } from '@/components/ui/Cinematic3DComparison';
import { CardBeforeAfterSlider } from '@/components/ui/CardBeforeAfterSlider'; import { CardBeforeAfterSlider } from '@/components/ui/CardBeforeAfterSlider';
import { ShiftableToolsGridSection } from '@/components/sections/ShiftableToolsGridSection'; import { ShiftableToolsGridSection } from '@/components/sections/ShiftableToolsGridSection';
import { TrendyBentoSection } from '@/components/sections/TrendyBentoSection';
describe('Before/After Comparison Sliders (Mobile & Touch Responsiveness)', () => { 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( const html = renderToString(
<Cinematic3DComparison <Cinematic3DComparison
beforeUrl="/before.jpg" beforeUrl="/before.jpg"
@@ -17,12 +18,13 @@ describe('Before/After Comparison Sliders (Mobile & Touch Responsiveness)', () =
); );
expect(html).toContain('role="slider"'); expect(html).toContain('role="slider"');
expect(html).toContain('aria-label="Before and after comparison"'); expect(html).toContain('aria-label="Before and after comparison slider"');
expect(html).toContain('touch-none'); expect(html).toContain('touch-none');
expect(html).toContain('touch-action:none'); expect(html).toContain('touch-action:none');
expect(html).toContain('touch-action:pan-y');
}); });
it('CardBeforeAfterSlider renders with touch-none, role="slider", and touchAction: none', () => { it('CardBeforeAfterSlider arrow handle has touch-none, role="slider", and touchAction: none', () => {
const html = renderToString( const html = renderToString(
<CardBeforeAfterSlider <CardBeforeAfterSlider
beforeUrl="/before.jpg" beforeUrl="/before.jpg"
@@ -34,10 +36,11 @@ describe('Before/After Comparison Sliders (Mobile & Touch Responsiveness)', () =
expect(html).toContain('aria-label="Before and after transformation slider"'); expect(html).toContain('aria-label="Before and after transformation slider"');
expect(html).toContain('touch-none'); expect(html).toContain('touch-none');
expect(html).toContain('touch-action:none'); expect(html).toContain('touch-action:none');
expect(html).toContain('touch-action:pan-y');
expect(html).toContain('--split:50%'); expect(html).toContain('--split:50%');
}); });
it('ShiftableToolsGridSection renders comparison sliders as standalone interactive cards with touch-action: none', () => { it('ShiftableToolsGridSection renders comparison cards as clickable links with handle-only slider dragging', () => {
const html = renderToString( const html = renderToString(
<ShiftableToolsGridSection /> <ShiftableToolsGridSection />
); );
@@ -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('aria-label="Before and after comparison slider"');
expect(html).toContain('touch-none'); expect(html).toContain('touch-none');
expect(html).toContain('touch-action: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(
<TrendyBentoSection />
);
expect(html).toContain('href="/tools/background-remover"');
expect(html).toContain('href="/tools/old-photo-restorer"');
expect(html).toContain('href="/tools/cartoon-avatar"');
}); });
}); });