Skip to content

Commit a07a48a

Browse files
committed
fix(pathways/swipe): prevent click event when dragging on desktop
Track drag distance and only trigger tap/click if user moved less than 5px. This prevents the detail popup from opening when swiping.
1 parent 311351e commit a07a48a

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

apps/registry/app/pathways/swipe/components/SwipeCard.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
'use client';
22

3+
import { useRef } from 'react';
34
import { motion, useMotionValue, useTransform } from 'framer-motion';
45
import { MapPin, Building2, DollarSign, Wifi } from 'lucide-react';
56

67
const SWIPE_THRESHOLD = 100;
8+
const TAP_THRESHOLD = 5; // Max pixels moved to count as a tap
79

810
export default function SwipeCard({
911
job,
@@ -13,12 +15,24 @@ export default function SwipeCard({
1315
isBackground = false,
1416
}) {
1517
const x = useMotionValue(0);
18+
const hasDragged = useRef(false);
1619

1720
// Transform x position to rotation and opacity
1821
const rotate = useTransform(x, [-200, 0, 200], [-15, 0, 15]);
1922
const likeOpacity = useTransform(x, [0, 100], [0, 1]);
2023
const nopeOpacity = useTransform(x, [-100, 0], [1, 0]);
2124

25+
const handleDragStart = () => {
26+
hasDragged.current = false;
27+
};
28+
29+
const handleDrag = (event, info) => {
30+
// Mark as dragged if moved beyond tap threshold
31+
if (Math.abs(info.offset.x) > TAP_THRESHOLD) {
32+
hasDragged.current = true;
33+
}
34+
};
35+
2236
const handleDragEnd = (event, info) => {
2337
if (info.offset.x > SWIPE_THRESHOLD) {
2438
onSwipeRight?.();
@@ -27,6 +41,13 @@ export default function SwipeCard({
2741
}
2842
};
2943

44+
const handleClick = () => {
45+
// Only trigger tap if user didn't drag
46+
if (!hasDragged.current) {
47+
onTap?.();
48+
}
49+
};
50+
3051
// Format salary display
3152
const formatSalary = () => {
3253
if (job.salaryMin && job.salaryMax) {
@@ -71,10 +92,12 @@ export default function SwipeCard({
7192
drag="x"
7293
dragConstraints={{ left: 0, right: 0 }}
7394
dragElastic={0.7}
95+
onDragStart={handleDragStart}
96+
onDrag={handleDrag}
7497
onDragEnd={handleDragEnd}
7598
style={{ x, rotate }}
7699
whileTap={{ scale: 0.98 }}
77-
onClick={onTap}
100+
onClick={handleClick}
78101
>
79102
{/* Like indicator */}
80103
<motion.div

0 commit comments

Comments
 (0)