Skip to content

Commit 35fbad7

Browse files
marker-daomarker dao ®
andauthored
Popup: Update toolbar integrationOptions with toolbarItems (T1312079) (#31744)
Co-authored-by: marker dao ® <[email protected]>
1 parent 42a7224 commit 35fbad7

File tree

2 files changed

+65
-7
lines changed

2 files changed

+65
-7
lines changed

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,16 @@ class Popup<
621621
return this._renderByTemplate(template, $container);
622622
}
623623

624+
_getIntegrationOptions(): Record<string, unknown> {
625+
// @ts-expect-error integrationOptions
626+
const { integrationOptions } = this.option();
627+
628+
return {
629+
...integrationOptions as Record<string, unknown>,
630+
skipTemplates: ['content', 'title'],
631+
};
632+
}
633+
624634
_renderByPolymorphicTemplate(
625635
items: ToolbarItem[],
626636
$container: dxElementWrapper,
@@ -633,11 +643,7 @@ class Popup<
633643
useFlatToolbarButtons,
634644
} = this.option();
635645

636-
const integrationOptions = extend(
637-
{},
638-
this.option('integrationOptions'),
639-
{ skipTemplates: ['content', 'title'] },
640-
);
646+
const integrationOptions = this._getIntegrationOptions();
641647

642648
const toolbarOptions = extend(additionalToolbarOptions, {
643649
disabled,
@@ -684,7 +690,17 @@ class Popup<
684690
_updateToolbarOptions(toolbar: string, options: Partial<ToolbarProperties>): void {
685691
const instance = toolbar === 'top' ? this._topToolbar : this._bottomToolbar;
686692

687-
instance?.option(options);
693+
if (!instance) {
694+
return;
695+
}
696+
697+
const integrationOptions = this._getIntegrationOptions();
698+
699+
// @ts-expect-error integrationOptions
700+
instance.option({
701+
...options,
702+
integrationOptions,
703+
});
688704
}
689705

690706
_toggleAriaLabel(): void {

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

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ import 'ui/date_box';
4040
const IS_SAFARI = !!browser.safari;
4141
const IS_IOS_DEVICE = devices.real().platform === 'ios';
4242
const IS_OLD_SAFARI = IS_SAFARI && compareVersions(browser.version, [11]) < 0;
43-
const PREVENT_SAFARI_SCROLLING_CLASS = 'dx-prevent-safari-scrolling';
4443

44+
const PREVENT_SAFARI_SCROLLING_CLASS = 'dx-prevent-safari-scrolling';
45+
const CUSTOM_ITEM_CLASS = 'custom-item-class';
4546
const TOOLBAR_LABEL_CLASS = 'dx-toolbar-label';
4647

4748
themes.setDefaultTimeout(0);
@@ -2826,6 +2827,10 @@ QUnit.module('rendering', {
28262827
QUnit.module('templates', {
28272828
beforeEach: function() {
28282829
executeAsyncMock.setup();
2830+
2831+
this.getInstance = () => $('#popup').dxPopup('instance');
2832+
this.getOverlayContent = () => this.getInstance().$overlayContent();
2833+
this.getCustomItem = () => this.getOverlayContent().find(`.${CUSTOM_ITEM_CLASS}`);
28292834
},
28302835
afterEach: function() {
28312836
executeAsyncMock.teardown();
@@ -3040,6 +3045,43 @@ QUnit.module('templates', {
30403045
assert.strictEqual(toolbarButtonText, buttonText, 'default content template rendered');
30413046
assert.strictEqual(toolbarTabTitleText, `${titleText}${titleText}`, 'default title template rendered');
30423047
});
3048+
3049+
QUnit.test('Popup toolbar should render custom template from integrationOptions after runtime toolbarItems change (T1312079)', function(assert) {
3050+
const popup = $('#popup').dxPopup({
3051+
visible: true,
3052+
showTitle: true,
3053+
title: 'Title',
3054+
}).dxPopup('instance');
3055+
3056+
const $customItemOnInit = this.getCustomItem();
3057+
3058+
assert.strictEqual($customItemOnInit.length, 0, 'custom template not rendered initially');
3059+
3060+
popup.option({
3061+
integrationOptions: {
3062+
templates: {
3063+
'customToolbarTemplate': {
3064+
render(args) {
3065+
$('<div>')
3066+
.attr('class', CUSTOM_ITEM_CLASS)
3067+
.appendTo(args.container);
3068+
},
3069+
},
3070+
},
3071+
},
3072+
toolbarItems: [
3073+
{
3074+
location: 'after',
3075+
toolbar: 'top',
3076+
template: 'customToolbarTemplate',
3077+
},
3078+
],
3079+
});
3080+
3081+
const $customItemAfterRuntimeChange = this.getCustomItem();
3082+
3083+
assert.strictEqual($customItemAfterRuntimeChange.length, 1, 'custom template rendered after runtime change');
3084+
});
30433085
});
30443086

30453087
QUnit.module('renderGeometry', {

0 commit comments

Comments
 (0)