Skip to content

Commit ee26f47

Browse files
authored
Popup: Move triggering of resize before animation
1 parent f02cd1c commit ee26f47

File tree

4 files changed

+68
-14
lines changed

4 files changed

+68
-14
lines changed

e2e/testcafe-devextreme/tests/editors/overlays/toolbarIntegration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ safeSizeTest('Popup toolbars with wide elements and overflow menu if hidden on i
216216
...baseConfiguration,
217217
toolbarItems: [],
218218
visible: false,
219-
}, undefined, { disableFxAnimation: true }));
219+
}, undefined, { disableFxAnimation: false }));
220220

221221
safeSizeTest('Popup toolbars with wide elements and overflow menu if shown on init with toolbar items', async (t) => {
222222
const { takeScreenshot, compareResults } = createScreenshotsComparer(t);

packages/devextreme/js/__internal/ui/overlay/m_overlay.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,6 @@ class Overlay<
687687
}
688688

689689
this._currentVisible = visible;
690-
691690
this._stopAnimation();
692691

693692
if (!visible) {
@@ -707,8 +706,8 @@ class Overlay<
707706
this._updateZIndexStackPosition(visible);
708707
this._moveFromContainer();
709708
}
710-
this._toggleShading(visible);
711709

710+
this._toggleShading(visible);
712711
this._toggleSubscriptions(visible);
713712
}
714713

packages/devextreme/js/__internal/ui/popup/m_popup.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ class Popup<
505505
} else {
506506
this._renderTopToolbarImpl();
507507
}
508-
this._triggerToolbarResizeEvent();
508+
509509
this._$topToolbar?.toggleClass(POPUP_HAS_CLOSE_BUTTON_CLASS, this._hasCloseButton());
510510
} else {
511511
this._$topToolbar?.detach();
@@ -553,7 +553,7 @@ class Popup<
553553
} else {
554554
this._renderBottomToolbarImpl();
555555
}
556-
this._triggerToolbarResizeEvent();
556+
557557
this._toggleClasses();
558558
}
559559

@@ -582,10 +582,13 @@ class Popup<
582582
}
583583

584584
_triggerToolbarResizeEvent(): void {
585-
// To trigger toolbar width set in initial rendering to set menu button width (T1245421)
586-
// And to trigger with animation in runtime items update
587-
triggerResizeEvent(this.$overlayContent());
588-
triggerResizeEvent(this.$overlayContent());
585+
// To trigger toolbar width to set overflow menu button width (T1245421)
586+
[this._$topToolbar, this._$bottomToolbar].forEach(($toolbar) => {
587+
if ($toolbar) {
588+
triggerResizeEvent($toolbar);
589+
triggerResizeEvent($toolbar);
590+
}
591+
});
589592
}
590593

591594
_renderToolbar(
@@ -679,6 +682,11 @@ class Popup<
679682
this.$overlayContent().attr('aria-labelledby', titleId);
680683
}
681684

685+
_animateShowing(): void {
686+
this._triggerToolbarResizeEvent();
687+
super._animateShowing();
688+
}
689+
682690
_renderVisibilityAnimate(visible: boolean): DeferredObj<unknown> | Promise<unknown> {
683691
return super._renderVisibilityAnimate(visible);
684692
}

packages/devextreme/testing/tests/DevExpress.ui.widgets/popup.tests.js

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,7 @@ QUnit.module('options changed callbacks', {
15091509
const topToolbar = this.instance.topToolbar();
15101510

15111511
assert.strictEqual(topToolbar.length, 1, 'top toolbar is rendered');
1512-
// 1st and 2nd from toolbar rendering on init, 3rd from overlay visibility changing
1512+
// 1st from overlay visibility changing, 2nd and 3rd from _animateShowing
15131513
assert.strictEqual(this.resizeEventSpy.callCount, 3, 'event is triggered 3 times');
15141514
});
15151515

@@ -1524,7 +1524,7 @@ QUnit.module('options changed callbacks', {
15241524
const topToolbar = this.instance.topToolbar();
15251525

15261526
assert.strictEqual(topToolbar.length, 1, 'top toolbar is rendered');
1527-
// 1st and 2nd from toolbar rendering on init, 3rd from overlay visibility changing
1527+
// 1st from overlay visibility changing, 2nd and 3rd from _animateShowing
15281528
assert.strictEqual(this.resizeEventSpy.callCount, 3, 'event is triggered 3 times');
15291529
});
15301530

@@ -1540,8 +1540,8 @@ QUnit.module('options changed callbacks', {
15401540
this.instance.option({ toolbarItems: [{ text: 'text' }] });
15411541

15421542
assert.strictEqual(getTopToolbar().length, 1, 'top toolbar is rendered');
1543-
// 2, 3 from top toolbar rendering, 4, 5 from optionChanged
1544-
assert.strictEqual(this.resizeEventSpy.callCount, 5, 'event is triggered 5 times');
1543+
// 2nd and 3rd from optionChanged
1544+
assert.strictEqual(this.resizeEventSpy.callCount, 3, 'event is triggered 3 times');
15451545
});
15461546

15471547
QUnit.test('toolbarItems runtime changing should trigger resize event if toolbar is rendered on init', function(assert) {
@@ -1559,10 +1559,57 @@ QUnit.module('options changed callbacks', {
15591559
const $toolbar2 = getTopToolbar();
15601560

15611561
assert.strictEqual($toolbar2.length, 1, 'top toolbar is rendered');
1562-
assert.strictEqual(this.resizeEventSpy.callCount, 7, 'event is triggered additional times');
1562+
assert.strictEqual(this.resizeEventSpy.callCount, 5, 'event is triggered additional times');
15631563

15641564
assert.strictEqual($toolbar1, $toolbar2, 'toolbar is not rendered twice after toolbarItems update in runtime');
15651565
});
1566+
1567+
QUnit.test('resize event is triggered during animation showing when toolbar is present', function(assert) {
1568+
this.resizeEventSpy.resetHistory();
1569+
this.reinit({
1570+
visible: false,
1571+
showTitle: true,
1572+
showCloseButton: true,
1573+
});
1574+
const beforeShow = this.resizeEventSpy.callCount;
1575+
1576+
this.instance.show();
1577+
1578+
const topToolbar = this.instance.topToolbar();
1579+
1580+
assert.strictEqual(beforeShow, 0, 'event is not triggered when popup is hidden');
1581+
assert.strictEqual(topToolbar.length, 1, 'top toolbar is rendered');
1582+
// 1st from overlay visibility changing, 2nd and 3rd from _animateShowing
1583+
assert.strictEqual(this.resizeEventSpy.callCount, 3, 'event is triggered 3 times during show animation');
1584+
});
1585+
1586+
QUnit.test('additional resize events are triggered only on toolbar elements', function(assert) {
1587+
this.resizeEventSpy.resetHistory();
1588+
this.reinit({
1589+
visible: true,
1590+
showTitle: true,
1591+
showCloseButton: true,
1592+
toolbarItems: [
1593+
{
1594+
text: 'bottom text',
1595+
toolbar: 'bottom',
1596+
location: 'center',
1597+
},
1598+
],
1599+
});
1600+
1601+
const topToolbar = this.instance.topToolbar();
1602+
const bottomToolbar = this.instance.bottomToolbar();
1603+
const overlayContent = this.instance.$overlayContent();
1604+
1605+
const callsForTopToolbar = this.resizeEventSpy.getCalls().filter(call => call.args[0] && call.args[0][0] === topToolbar[0]);
1606+
const callsForBottomToolbar = this.resizeEventSpy.getCalls().filter(call => call.args[0] && call.args[0][0] === bottomToolbar[0]);
1607+
const callsForOverlayContent = this.resizeEventSpy.getCalls().filter(call => call.args[0] && call.args[0][0] === overlayContent[0]);
1608+
1609+
assert.strictEqual(callsForTopToolbar.length, 2, 'additional resize events are triggered on top toolbar');
1610+
assert.strictEqual(callsForBottomToolbar.length, 2, 'additional resize events are triggered on bottom toolbar');
1611+
assert.strictEqual(callsForOverlayContent.length, 1, 'resize event is triggered on overlay content for geometry rendering');
1612+
});
15661613
});
15671614

15681615
QUnit.test('titleTemplate option change should trigger resize event for content correct geometry rendering', function(assert) {

0 commit comments

Comments
 (0)