Fix mobile tap selection double-trigger (Issue #54)#55
Merged
ysgrProgramming merged 1 commit intoNov 27, 2025
Merged
Conversation
- Add touchHandledRef to track when touch events are handled - Prevent synthetic click events from firing after touch taps - Ignore synthetic click events in onClick handler when touch was handled - Add tests to verify selection persists after tap without double-trigger - Add test to verify deselection works correctly with double tap Closes #54
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes Issue #54: On touch devices, selecting a piece causes the selection highlight to flash briefly and immediately disappear due to double-triggering from synthetic click events.
Root Cause
handleTouchEndinvokeshandleSquareClickto emulate a tapclickevent, which also triggershandleSquareClickvia theonClickhandlerSolution
touchHandledRefto track when touch events are handledevent.preventDefault()inhandleTouchEndwhen handling taps to prevent synthetic clickonClickhandler whentouchHandledRef.currentis trueChanges
src/components/ChessBoard.tsx: Added touch handling flag and preventDefault logictests/components/ChessBoard.responsive.test.tsx: Added tests for selection persistence and double-tap deselectionTesting
Self-Walkthrough
Requirements Mapping
event.preventDefault()inhandleTouchEndshould maintain selection after tap without double-triggering from synthetic clicktouchHandledRefis only set for touch eventsCode Logic
touchHandledRef.current = trueand callevent.preventDefault()to prevent synthetic clickonClickhandler checkstouchHandledRef.currentand returns early if true, preventing double-triggerhandleTouchStartto ensure clean state for each touch sequenceCloses #54