Skip to content

Commit d9f7221

Browse files
fix: do not bubble drag events to parent dialogs (#11525) (#11527)
Co-authored-by: Sascha Ißbrücker <sissbruecker@vaadin.com>
1 parent e4055ae commit d9f7221

2 files changed

Lines changed: 67 additions & 6 deletions

File tree

packages/dialog/src/vaadin-dialog-draggable-mixin.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ export const DialogDraggableMixin = (superClass) =>
103103
this.top = top;
104104
this.left = left;
105105
}
106-
this.dispatchEvent(
107-
new CustomEvent('drag-start', { bubbles: true, composed: true, detail: { width, height, top, left } }),
108-
);
106+
this.dispatchEvent(new CustomEvent('drag-start', { detail: { width, height, top, left } }));
109107
}
110108
}
111109
}
@@ -135,9 +133,7 @@ export const DialogDraggableMixin = (superClass) =>
135133

136134
/** @private */
137135
_stopDrag() {
138-
this.dispatchEvent(
139-
new CustomEvent('dragged', { bubbles: true, composed: true, detail: { top: this.top, left: this.left } }),
140-
);
136+
this.dispatchEvent(new CustomEvent('dragged', { detail: { top: this.top, left: this.left } }));
141137
window.removeEventListener('mouseup', this._stopDrag);
142138
window.removeEventListener('touchend', this._stopDrag);
143139
window.removeEventListener('mousemove', this._drag);

packages/dialog/test/draggable-resizable.test.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,71 @@ describe('nested draggable dialogs', () => {
849849
expect(Math.floor(childDraggedBounds.top)).to.be.eql(Math.floor(childBounds.top));
850850
expect(Math.floor(childDraggedBounds.left)).to.be.eql(Math.floor(childBounds.left));
851851
});
852+
853+
it('should not bubble "drag-start" event to parent dialog', () => {
854+
const spy = sinon.spy();
855+
parentDialog.addEventListener('drag-start', spy);
856+
857+
drag(childHeader, dx, dx);
858+
859+
expect(spy.called).to.be.false;
860+
});
861+
862+
it('should not bubble "dragged" event to parent dialog', () => {
863+
const spy = sinon.spy();
864+
parentDialog.addEventListener('dragged', spy);
865+
866+
drag(childHeader, dx, dx);
867+
868+
expect(spy.called).to.be.false;
869+
});
870+
});
871+
872+
describe('nested resizable dialogs', () => {
873+
let parentDialog, childDialog, childResizer, dx;
874+
875+
beforeEach(async () => {
876+
parentDialog = fixtureSync('<vaadin-dialog resizable opened></vaadin-dialog>');
877+
await nextRender();
878+
879+
parentDialog.renderer = (root) => {
880+
if (!root.firstChild) {
881+
root.innerHTML = '<div>Parent dialog content</div>';
882+
883+
childDialog = document.createElement('vaadin-dialog');
884+
childDialog.resizable = true;
885+
childDialog.renderer = (childRoot) => {
886+
childRoot.innerHTML = '<div>Child dialog content</div>';
887+
};
888+
root.appendChild(childDialog);
889+
}
890+
};
891+
await nextUpdate(parentDialog);
892+
893+
childDialog.opened = true;
894+
await nextRender();
895+
896+
childResizer = childDialog.$.overlay.$.overlay.querySelector('.se');
897+
dx = 30;
898+
});
899+
900+
it('should not bubble "resize-start" event to parent dialog', () => {
901+
const spy = sinon.spy();
902+
parentDialog.addEventListener('resize-start', spy);
903+
904+
resize(childResizer, dx, dx);
905+
906+
expect(spy.called).to.be.false;
907+
});
908+
909+
it('should not bubble "resize" event to parent dialog', () => {
910+
const spy = sinon.spy();
911+
parentDialog.addEventListener('resize', spy);
912+
913+
resize(childResizer, dx, dx);
914+
915+
expect(spy.called).to.be.false;
916+
});
852917
});
853918

854919
describe('touch', () => {

0 commit comments

Comments
 (0)