Skip to content

Commit de7797a

Browse files
vaadin-botsissbrueckerweb-padawan
authored
fix: set dialog position on drag start (#10191) (CP: 24.9) (#10196)
* fix: set dialog position on drag start (#10191) * fix: align setting bounds with v25, remove not needed tests --------- Co-authored-by: Sascha Ißbrücker <sissbruecker@vaadin.com> Co-authored-by: web-padawan <iamkulykov@gmail.com>
1 parent d117fba commit de7797a

File tree

3 files changed

+35
-23
lines changed

3 files changed

+35
-23
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ export const DialogDraggableMixin = (superClass) =>
9595
window.addEventListener('touchmove', this._drag);
9696
if (this.$.overlay.$.overlay.style.position !== 'absolute') {
9797
const { top, left } = this._originalBounds;
98-
this.$.overlay.setBounds({ top, left });
98+
this.top = top;
99+
this.left = left;
99100
}
100101
}
101102
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ export const DialogResizableMixin = (superClass) =>
7272
window.addEventListener('touchmove', this._resizeListeners.resize[direction]);
7373
window.addEventListener('mouseup', this._resizeListeners.stop[direction]);
7474
window.addEventListener('touchend', this._resizeListeners.stop[direction]);
75-
if (this.$.overlay.$.overlay.style.position !== 'absolute' || this.width || this.height) {
76-
this.$.overlay.setBounds(this._originalBounds);
77-
}
78-
75+
this.$.overlay.setBounds(this._originalBounds);
7976
this.$.overlay.setAttribute('has-bounds-set', '');
8077
}
8178
}

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

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,6 @@ describe('resizable', () => {
305305
expect(Math.floor(resizedBounds.width)).to.be.eql(Math.floor(bounds.width + dx));
306306
});
307307

308-
it('should not set bounds again after position is set to absolute', () => {
309-
const spy = sinon.spy(dialog.$.overlay, 'setBounds');
310-
dispatchMouseEvent(overlayPart.querySelector('.n'), 'mousedown');
311-
dialog.$.overlay.$.overlay.style.position = 'absolute';
312-
dispatchMouseEvent(overlayPart.querySelector('.n'), 'mousedown');
313-
expect(spy.calledOnce).to.be.true;
314-
});
315-
316308
it('should dispatch resize event with correct details', () => {
317309
const onResize = sinon.spy();
318310
const content = dialog.$.overlay.$.content;
@@ -440,8 +432,9 @@ describe('draggable', () => {
440432
expect(Math.floor(draggedBounds.left)).to.be.eql(Math.floor(bounds.left + dx));
441433
});
442434

443-
it('should only change "position", "top", and "left" values on drag', () => {
435+
it('should only change "position", "top", and "left" values on drag', async () => {
444436
drag(content);
437+
await nextRender();
445438
const overlay = dialog.$.overlay.$.overlay;
446439
const style = overlay.style;
447440
expect(style.length).to.be.eql(3);
@@ -450,6 +443,18 @@ describe('draggable', () => {
450443
expect(style.left).to.be.ok;
451444
});
452445

446+
it('should assign "top", and "left" properties on drag start', async () => {
447+
const overlayBounds = dialog.$.overlay.getBounds();
448+
expect(dialog.left).to.be.undefined;
449+
expect(dialog.top).to.be.undefined;
450+
451+
dispatchMouseEvent(content, 'mousedown');
452+
await nextRender();
453+
454+
expect(dialog.left).to.be.equal(overlayBounds.left);
455+
expect(dialog.top).to.be.equal(overlayBounds.top);
456+
});
457+
453458
it('should drag and move dialog if mousedown on element with [class="draggable"] in another shadow root', async () => {
454459
drag(dialog.$.overlay.querySelector('internally-draggable').shadowRoot.querySelector('.draggable'));
455460
await nextRender();
@@ -532,7 +537,7 @@ describe('draggable', () => {
532537
expect(Math.floor(draggedBounds.left)).to.be.eql(Math.floor(bounds.left));
533538
});
534539

535-
it('should not drag dialog if mousedown on .resizer-container scrollbar', () => {
540+
it('should not drag dialog if mousedown on .resizer-container scrollbar', async () => {
536541
const boundsSpy = sinon.spy(dialog.$.overlay, 'setBounds');
537542
content.style.width = `${content.clientWidth * 4}px`;
538543
const scrollbarHeight = container.offsetHeight - container.clientHeight;
@@ -541,6 +546,7 @@ describe('draggable', () => {
541546
x: containerBounds.left + containerBounds.width / 2,
542547
y: containerBounds.top + containerBounds.height - scrollbarHeight / 2,
543548
});
549+
await nextRender();
544550
expect(boundsSpy.called).to.equal(!scrollbarHeight);
545551
});
546552

@@ -578,14 +584,6 @@ describe('draggable', () => {
578584
expect(Math.floor(draggedBounds.height)).to.be.eql(Math.floor(bounds.height));
579585
});
580586

581-
it('should not update overlay bounds with position: absolute', () => {
582-
const spy = sinon.spy(dialog.$.overlay, 'setBounds');
583-
dispatchMouseEvent(content, 'mousedown');
584-
dialog.$.overlay.$.overlay.style.position = 'absolute';
585-
dispatchMouseEvent(content, 'mousedown');
586-
expect(spy.calledOnce).to.be.true;
587-
});
588-
589587
it('should not reset scroll position on dragstart', async () => {
590588
dialog.modeless = true;
591589
button.style.marginBottom = '200px';
@@ -617,6 +615,22 @@ describe('draggable', () => {
617615
expect(detail.left).to.be.equal(dialog.left);
618616
});
619617

618+
it('should use correct coordinates in "dragged" event without moving the dialog during drag', async () => {
619+
const overlayBounds = dialog.$.overlay.getBounds();
620+
const onDragged = sinon.spy();
621+
dialog.addEventListener('dragged', onDragged);
622+
623+
dispatchMouseEvent(content, 'mousedown');
624+
await nextRender();
625+
dispatchMouseEvent(content, 'mouseup');
626+
await nextRender();
627+
628+
expect(onDragged.calledOnce).to.be.true;
629+
const { detail } = onDragged.args[0][0];
630+
expect(detail.top).to.be.equal(overlayBounds.top);
631+
expect(detail.left).to.be.equal(overlayBounds.left);
632+
});
633+
620634
it('should not set overlay max-width to none on drag', async () => {
621635
drag(container);
622636
await nextRender();

0 commit comments

Comments
 (0)