Skip to content

Commit

Permalink
fix: support dragging from a draggable node inside another shadow root (
Browse files Browse the repository at this point in the history
  • Loading branch information
tomivirkki committed Sep 8, 2020
1 parent 5b97b51 commit b12df86
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/vaadin-dialog-draggable-mixin.html
Expand Up @@ -24,6 +24,11 @@
_touchDevice: {
type: Boolean,
value: TOUCH_DEVICE
},

/* TODO: Expose as a public property (check naming) */
__dragHandleClassName: {
type: String
}
};
}
Expand All @@ -50,7 +55,10 @@
const isResizerContainer = e.target === resizerContainer;
const isResizerContainerScrollbar = e.offsetX > resizerContainer.clientWidth || e.offsetY > resizerContainer.clientHeight;
const isContentPart = e.target === this.$.overlay.$.content;
const isDraggable = e.target.classList.contains('draggable');
const isDraggable = e.composedPath().some(node => {
return node.classList && node.classList.contains(this.__dragHandleClassName || 'draggable');
});

if ((isResizerContainer && !isResizerContainerScrollbar) || isContentPart || isDraggable) {
!isDraggable && e.preventDefault();
this._originalBounds = this._getOverlayBounds();
Expand Down
1 change: 1 addition & 0 deletions test/.eslintrc.json
Expand Up @@ -3,6 +3,7 @@
"WCT": false,
"describe": false,
"beforeEach": false,
"before": false,
"fixture": false,
"it": false,
"expect": false,
Expand Down
18 changes: 18 additions & 0 deletions test/vaadin-dialog_draggable-resizable-test.html
Expand Up @@ -7,6 +7,8 @@
<link rel="import" href="../../test-fixture/test-fixture.html">
<link rel="import" href="../../iron-test-helpers/iron-test-helpers.html">
<link rel="import" href="../src/vaadin-dialog.html">
<link rel="import" href="../../polymer/polymer-element.html">
<link rel="import" href="../../polymer/lib/utils/html-tag.html">
</head>

<body>
Expand Down Expand Up @@ -58,6 +60,7 @@
<template>
<div>Draggable dialog</div>
<div class="draggable">Draggable area</div>
<internally-draggable></internally-draggable>
<button>OK</button>
</template>
</vaadin-dialog>
Expand Down Expand Up @@ -435,6 +438,14 @@
dispatchMouseEvent(target, 'mouseup', toXY, mouseButton);
}

before(() => {
customElements.define('internally-draggable', class extends Polymer.Element {
static get template() {
return Polymer.html`<div class="draggable">draggable</div>`;
}
});
});

beforeEach(() => {
dialog = fixture('draggable');
container = dialog.$.overlay.$.resizerContainer;
Expand Down Expand Up @@ -465,6 +476,13 @@
expect(Math.floor(draggedBounds.left)).to.be.eql(Math.floor(bounds.left + dx));
});

it('should drag and move dialog if mousedown on element with [class="draggable"] in another shadow root', () => {
drag(dialog.$.overlay.querySelector('internally-draggable').shadowRoot.querySelector('.draggable'));
const draggedBounds = container.getBoundingClientRect();
expect(Math.floor(draggedBounds.top)).to.be.eql(Math.floor(bounds.top + dx));
expect(Math.floor(draggedBounds.left)).to.be.eql(Math.floor(bounds.left + dx));
});

it('should drag and move dialog after resizing', () => {
resize(container.querySelector('.s'), 0, dx);
const bounds = container.getBoundingClientRect();
Expand Down

0 comments on commit b12df86

Please sign in to comment.