Skip to content

Commit 5e5eb22

Browse files
committed
Improve touch interactions and prevent page scroll
Prevent unintended page scrolling and selection during canvas interactions by adding CSS touch-action and user-select restrictions to canvas elements. JS touch handling now adds a body class (interaction-active) on touch start and removes it on touch end, and stops immediate propagation to better contain touch events. Also minor formatting/comment placement tweaks for clarity.
1 parent 712fe39 commit 5e5eb22

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

custom_components/esphome_designer/frontend/css/canvas.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@
112112
will-change: transform;
113113
transform-style: preserve-3d;
114114
touch-action: none;
115+
-webkit-user-select: none;
116+
user-select: none;
115117
}
116118

117119
.canvas-stage {
@@ -123,6 +125,7 @@
123125
min-width: max-content;
124126
position: relative;
125127
z-index: 10;
128+
touch-action: none;
126129
}
127130

128131
.artboard-wrapper {
@@ -175,7 +178,8 @@
175178
font-size: 10px;
176179
font-weight: 600;
177180
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
178-
cursor: grab; /* Indicates page can be moved */
181+
cursor: grab;
182+
/* Indicates page can be moved */
179183
}
180184

181185
.artboard-header:active {
@@ -237,6 +241,7 @@
237241
flex-shrink: 0;
238242
cursor: crosshair;
239243
transition: box-shadow 0.4s var(--t-base), transform 0.4s var(--t-base);
244+
touch-action: none;
240245
}
241246

242247
.canvas-viewport.with-rulers {

custom_components/esphome_designer/frontend/js/core/canvas_touch.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ export function setupTouchInteractions(canvasInstance) {
1515
const touches = ev.touches;
1616
const rect = canvasInstance.viewport.getBoundingClientRect();
1717

18+
// Lock page scrolling during active interaction
19+
document.body.classList.add("interaction-active");
20+
ev.stopImmediatePropagation();
21+
1822
if (touches.length === 2) {
1923
ev.preventDefault();
2024

@@ -267,6 +271,8 @@ function onTouchEnd(ev, canvasInstance) {
267271
window.removeEventListener("touchend", canvasInstance._boundTouchEnd);
268272
window.removeEventListener("touchcancel", canvasInstance._boundTouchEnd);
269273

274+
document.body.classList.remove("interaction-active");
275+
270276
render(canvasInstance);
271277
clearSnapGuides(canvasInstance);
272278
}

0 commit comments

Comments
 (0)