Skip to content

Commit 1a67608

Browse files
authored
fix: support dragging from a draggable node inside another shadow root (#188) (#189)
1 parent 5b97b51 commit 1a67608

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

src/vaadin-dialog-draggable-mixin.html

+9-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
_touchDevice: {
2525
type: Boolean,
2626
value: TOUCH_DEVICE
27+
},
28+
29+
/* TODO: Expose as a public property (check naming) */
30+
__dragHandleClassName: {
31+
type: String
2732
}
2833
};
2934
}
@@ -50,7 +55,10 @@
5055
const isResizerContainer = e.target === resizerContainer;
5156
const isResizerContainerScrollbar = e.offsetX > resizerContainer.clientWidth || e.offsetY > resizerContainer.clientHeight;
5257
const isContentPart = e.target === this.$.overlay.$.content;
53-
const isDraggable = e.target.classList.contains('draggable');
58+
const isDraggable = e.composedPath().some(node => {
59+
return node.classList && node.classList.contains(this.__dragHandleClassName || 'draggable');
60+
});
61+
5462
if ((isResizerContainer && !isResizerContainerScrollbar) || isContentPart || isDraggable) {
5563
!isDraggable && e.preventDefault();
5664
this._originalBounds = this._getOverlayBounds();

test/.eslintrc.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"WCT": false,
44
"describe": false,
55
"beforeEach": false,
6+
"before": false,
67
"fixture": false,
78
"it": false,
89
"expect": false,

test/vaadin-dialog_draggable-resizable-test.html

+18
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
<link rel="import" href="../../test-fixture/test-fixture.html">
88
<link rel="import" href="../../iron-test-helpers/iron-test-helpers.html">
99
<link rel="import" href="../src/vaadin-dialog.html">
10+
<link rel="import" href="../../polymer/polymer-element.html">
11+
<link rel="import" href="../../polymer/lib/utils/html-tag.html">
1012
</head>
1113

1214
<body>
@@ -58,6 +60,7 @@
5860
<template>
5961
<div>Draggable dialog</div>
6062
<div class="draggable">Draggable area</div>
63+
<internally-draggable></internally-draggable>
6164
<button>OK</button>
6265
</template>
6366
</vaadin-dialog>
@@ -435,6 +438,14 @@
435438
dispatchMouseEvent(target, 'mouseup', toXY, mouseButton);
436439
}
437440

441+
before(() => {
442+
customElements.define('internally-draggable', class extends Polymer.Element {
443+
static get template() {
444+
return Polymer.html`<div class="draggable">draggable</div>`;
445+
}
446+
});
447+
});
448+
438449
beforeEach(() => {
439450
dialog = fixture('draggable');
440451
container = dialog.$.overlay.$.resizerContainer;
@@ -465,6 +476,13 @@
465476
expect(Math.floor(draggedBounds.left)).to.be.eql(Math.floor(bounds.left + dx));
466477
});
467478

479+
it('should drag and move dialog if mousedown on element with [class="draggable"] in another shadow root', () => {
480+
drag(dialog.$.overlay.querySelector('internally-draggable').shadowRoot.querySelector('.draggable'));
481+
const draggedBounds = container.getBoundingClientRect();
482+
expect(Math.floor(draggedBounds.top)).to.be.eql(Math.floor(bounds.top + dx));
483+
expect(Math.floor(draggedBounds.left)).to.be.eql(Math.floor(bounds.left + dx));
484+
});
485+
468486
it('should drag and move dialog after resizing', () => {
469487
resize(container.querySelector('.s'), 0, dx);
470488
const bounds = container.getBoundingClientRect();

0 commit comments

Comments
 (0)