Skip to content

Commit 2cbe4a4

Browse files
committed
fix: onSquareClick not always working on mobile devices
1 parent 3cf1407 commit 2cbe4a4

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/Square.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ export const Square = memo(function Square({
8181
});
8282
}
8383
}}
84+
onTouchEnd={(e) => {
85+
// Prevent default to avoid double-firing with onClick on some devices
86+
e.preventDefault();
87+
onSquareClick?.({
88+
piece: currentPosition[squareId] ?? null,
89+
square: squareId,
90+
});
91+
}}
8492
onContextMenu={(e) => {
8593
e.preventDefault();
8694
onSquareRightClick?.({

0 commit comments

Comments
 (0)