Fix erratic mouse behavior in the swipe (slider) compare view#56
Merged
Conversation
The before/after slider had two classic pointer bugs: - The screenshots are normal <img> elements, draggable by default, and pointerdown never called preventDefault. Mousedown-then-move started a native image drag instead of moving the divider. - That native drag fires pointercancel, not pointerup, and only pointerup was handled — so `dragging` never reset and the divider then tracked the cursor on plain hover with no button held. Apply the standard guards used by image-comparison sliders: - preventDefault on pointerdown; respond to the primary button only. - End the drag on pointerup AND pointercancel/lostpointercapture, and release the pointer capture, so an interrupted gesture can't get stuck. - Make the images non-draggable and non-interactive (draggable="false", pointer-events:none, user-select/-webkit-user-drag:none) so the stage is always the pointer target and can't be hijacked by a native image drag. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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.
Symptom
In the swipe (slider) compare view, dragging the divider with a mouse feels erratic — the divider can jump, lag, or start following the cursor with no button held down.
Cause
Two classic before/after-slider pointer bugs in
buildSwipe:<img>elements (draggableby default), andpointerdownnever calledpreventDefault()— so mousedown-then-move starts a native image drag (ghost image, "no-drop" cursor) instead of moving the divider.pointercancel, notpointerup, and onlypointerupwas handled — sodraggingnever reset tofalse, and afterwards the divider tracks the cursor on plain hover.Fix
The standard guards used by image-comparison sliders (
img-comparison-slider, Juxtapose, cocoen):preventDefault()onpointerdown; respond to the primary button only.pointerupandpointercancel/lostpointercapture, and release the pointer capture — an interrupted gesture can no longer get stuck.draggable="false",pointer-events: none,user-select/-webkit-user-drag: none. The stage div is now the only pointer target, so a native image drag can't start.Test plan
npm run lint— cleannpm test— 111 passpointercancelmid-gesture leaves nothing stuck, images reportdraggable=false/pointer-events:none, and there are no console errors.🤖 Generated with Claude Code