Skip to content

Commit 51f010d

Browse files
authored
fix: don't prevent touchmove events inside the dialog (#164) (#166)
1 parent 6af2cbe commit 51f010d

File tree

4 files changed

+17
-19
lines changed

4 files changed

+17
-19
lines changed

src/vaadin-dialog-draggable-mixin.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,19 @@
4040
}
4141

4242
_startDrag(e) {
43+
// Don't initiate when there's more than 1 touch (pinch zoom)
44+
if (e.type === 'touchstart' && e.touches.length > 1) {
45+
return;
46+
}
47+
4348
if (this.draggable && (e.button === 0 || e.touches)) {
4449
const resizerContainer = this.$.overlay.$.resizerContainer;
4550
const isResizerContainer = e.target === resizerContainer;
4651
const isResizerContainerScrollbar = e.offsetX > resizerContainer.clientWidth || e.offsetY > resizerContainer.clientHeight;
4752
const isContentPart = e.target === this.$.overlay.$.content;
4853
const isDraggable = e.target.classList.contains('draggable');
4954
if ((isResizerContainer && !isResizerContainerScrollbar) || isContentPart || isDraggable) {
50-
// Is needed to prevent text selection in Safari
51-
!this._touchDevice && !isDraggable && e.preventDefault();
55+
!isDraggable && e.preventDefault();
5256
this._originalBounds = this._getOverlayBounds();
5357
const event = this.__getMouseOrFirstTouchEvent(e);
5458
this._originalMouseCoords = {top: event.pageY, left: event.pageX};
@@ -65,8 +69,7 @@
6569

6670
_drag(e) {
6771
const event = this.__getMouseOrFirstTouchEvent(e);
68-
if (this._eventInWindow(event) &&
69-
(e.type !== 'touchmove' || e.type === 'touchmove' && e.touches.length < 2)) {
72+
if (this._eventInWindow(event)) {
7073
const top = this._originalBounds.top + (event.pageY - this._originalMouseCoords.top);
7174
const left = this._originalBounds.left + (event.pageX - this._originalMouseCoords.left);
7275
this._setBounds({top, left});

src/vaadin-dialog-resizable-mixin.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@
132132
}
133133

134134
_startResize(e, direction) {
135+
// Don't initiate when there's more than 1 touch (pinch zoom)
136+
if (e.type === 'touchstart' && e.touches.length > 1) {
137+
return;
138+
}
139+
135140
if (e.button === 0 || e.touches) {
136141
e.preventDefault();
137142
this._originalBounds = this._getOverlayBounds();
@@ -149,8 +154,7 @@
149154

150155
_resize(e, resizer) {
151156
const event = this.__getMouseOrFirstTouchEvent(e);
152-
if (this._eventInWindow(event) &&
153-
(e.type !== 'touchmove' || e.type === 'touchmove' && e.touches.length < 2)) {
157+
if (this._eventInWindow(event)) {
154158
const minimumSize = 40;
155159
resizer.split('').forEach((direction) => {
156160
switch (direction) {

src/vaadin-dialog.html

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,6 @@
277277
this._observer = new Polymer.FlattenedNodesObserver(this, info => {
278278
this._setTemplateFromNodes(info.addedNodes);
279279
});
280-
281-
// We need to prevent dragging behind the non-draggable content of the dialog (i.e slotted text / button)
282-
this.$.overlay.$.content.addEventListener('touchmove', this._preventMove, {passive: false});
283-
}
284-
285-
_preventMove(e) {
286-
if (e.touches.length < 2) {
287-
e.preventDefault();
288-
}
289280
}
290281

291282
_setTemplateFromNodes(nodes) {

test/vaadin-dialog_draggable-resizable-test.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@
512512
y: Math.floor(bounds.top + (bounds.height / 2))
513513
};
514514
const toXY = {x: fromXY.x + dx, y: fromXY.y + dx};
515-
dispatchTouchEvent(target, 'touchstart', fromXY);
515+
dispatchTouchEvent(target, 'touchstart', fromXY, multitouch);
516516
dispatchTouchEvent(target, 'touchmove', toXY, multitouch);
517517
dispatchTouchEvent(target, 'touchend', toXY);
518518
}
@@ -525,7 +525,7 @@
525525
};
526526

527527
const toXY = {x: fromXY.x + dx, y: fromXY.y + dy};
528-
dispatchTouchEvent(target, 'touchstart', fromXY);
528+
dispatchTouchEvent(target, 'touchstart', fromXY, multitouch);
529529
dispatchTouchEvent(target, 'touchmove', toXY, multitouch);
530530
dispatchTouchEvent(target, 'touchend', toXY);
531531
}
@@ -558,9 +558,9 @@
558558
expect(e.defaultPrevented).to.be.true;
559559
});
560560

561-
it('should prevent default of the touchmove when dragged', () => {
561+
it('should not prevent default of the touchmove events', () => {
562562
const e = dispatchTouchEvent(draggableOverlay.$.content, 'touchmove');
563-
expect(e.defaultPrevented).to.be.true;
563+
expect(e.defaultPrevented).to.be.false;
564564
});
565565

566566
it('should bring to front on touch start', () => {

0 commit comments

Comments
 (0)