Skip to content

Commit ca865f5

Browse files
authored
fix: support dragging from a draggable node inside another shadow root (#188)
1 parent 43bc643 commit ca865f5

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
@@ -25,6 +25,11 @@
2525
_touchDevice: {
2626
type: Boolean,
2727
value: TOUCH_DEVICE
28+
},
29+
30+
/* TODO: Expose as a public property (check naming) */
31+
__dragHandleClassName: {
32+
type: String
2833
}
2934
};
3035
}
@@ -53,7 +58,10 @@
5358
const isResizerContainer = e.target === resizerContainer;
5459
const isResizerContainerScrollbar = e.offsetX > resizerContainer.clientWidth || e.offsetY > resizerContainer.clientHeight;
5560
const isContentPart = e.target === this.$.overlay.$.content;
56-
const isDraggable = e.target.classList.contains('draggable');
61+
const isDraggable = e.composedPath().some(node => {
62+
return node.classList && node.classList.contains(this.__dragHandleClassName || 'draggable');
63+
});
64+
5765
if ((isResizerContainer && !isResizerContainerScrollbar) || isContentPart || isDraggable) {
5866
!isDraggable && e.preventDefault();
5967
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
@@ -8,6 +8,8 @@
88
<link rel="import" href="../../iron-test-helpers/iron-test-helpers.html">
99
<link rel="import" href="../src/vaadin-dialog.html">
1010
<link rel="import" href="../../vaadin-text-field/vaadin-text-area.html">
11+
<link rel="import" href="../../polymer/polymer-element.html">
12+
<link rel="import" href="../../polymer/lib/utils/html-tag.html">
1113
</head>
1214

1315
<body>
@@ -59,6 +61,7 @@
5961
<template>
6062
<div>Draggable dialog</div>
6163
<div class="draggable">Draggable area</div>
64+
<internally-draggable></internally-draggable>
6265
<button>OK</button>
6366
</template>
6467
</vaadin-dialog>
@@ -436,6 +439,14 @@
436439
dispatchMouseEvent(target, 'mouseup', toXY, mouseButton);
437440
}
438441

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

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

0 commit comments

Comments
 (0)