Enable dragging popup panels via touch on mobile#30
Merged
Conversation
The draggable panels only listened for mouse events, so they could not be moved on touch devices. Add matching touchstart/touchmove/ touchend handlers and read coordinates from either event type. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds touch input support to the existing draggable popup panel system so panels can be repositioned on mobile/touch devices, aligning behavior between desktop/Electron and the browser/mobile experience.
Changes:
- Registers
touchstart/touchmove/touchend/touchcancelhandlers alongside existing mouse drag handlers. - Introduces a
getPoint()helper to share coordinate extraction logic between mouse and touch events. - Prevents page scrolling during an active touch drag via
preventDefault()and non-passivetouchmove.
Comment on lines
35
to
41
| if (e.target === header) { | ||
| isDragging = true; | ||
| // Prevent the page from scrolling while dragging on touch. | ||
| if (e.type === 'touchstart') { | ||
| e.preventDefault(); | ||
| } | ||
| } |
Comment on lines
+16
to
+20
| // Touch support so panels can be dragged on mobile devices too. | ||
| header.addEventListener('touchstart', dragStart, { passive: false }); | ||
| document.addEventListener('touchmove', drag, { passive: false }); | ||
| document.addEventListener('touchend', dragEnd); | ||
| document.addEventListener('touchcancel', dragEnd); |
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
The draggable popup panels (ElemCo input, orbital controls, XYZ editor, preferences, xtb) could be moved by dragging their headers on desktop and in the Electron app, but not on touch devices.
Cause
makeDraggableinjs/ui.jsonly registeredmousedown/mousemove/mouseup, which don't fire for touch interactions.Fix
Added matching
touchstart/touchmove/touchend/touchcancelhandlers that share the existing drag logic, plus a smallgetPoint()helper that reads coordinates frome.touches[0](touch) ore.clientX/Y(mouse).touchmoveuses{ passive: false }andpreventDefault()so the page doesn't scroll while a panel is being dragged.Applies to all five panels since they share the same helper. No CSS changes.
Testing
On a phone (or browser device emulation), open the ElemCo panel and drag it by its header — it now moves just like on desktop.
🤖 Generated with Claude Code