Skip to content

Commit d5a839f

Browse files
authored
DropDownButton: Remove content template from Popup integrationOptions (T1294338)
1 parent 2d1dd0b commit d5a839f

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

packages/devextreme/js/__internal/ui/m_drop_down_button.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,12 @@ class DropDownButton extends Widget<DropDownButtonProperties> {
375375
this._popupContentId = `dx-${new Guid()}`;
376376
this.setAria('id', this._popupContentId, $content);
377377

378-
return template.render({
378+
const result = template.render({
379379
container: getPublicElement($content),
380380
model: this.option('items') || this._dataController.getDataSource(),
381381
});
382+
383+
return result;
382384
}
383385

384386
_popupOptions() {
@@ -412,6 +414,7 @@ class DropDownButton extends Widget<DropDownButtonProperties> {
412414
at: `${horizontalAlignment} bottom`,
413415
},
414416
_wrapperClassExternal: DROP_DOWN_EDITOR_OVERLAY_CLASS,
417+
contentTemplate: null,
415418
}, this._options.cache('dropDownOptions'), { visible: this.option('opened') });
416419
}
417420

@@ -583,19 +586,20 @@ class DropDownButton extends Widget<DropDownButtonProperties> {
583586
this.$element().toggleClass(DROP_DOWN_BUTTON_HAS_ARROW_CLASS, hasArrow);
584587
}
585588

586-
toggle(visible?: boolean) {
589+
toggle(visible?: boolean): Promise<unknown> | undefined {
587590
if (!this._popup) {
588591
this._renderPopup();
589592
this._renderContent();
590593
}
594+
591595
return this._popup?.toggle(visible);
592596
}
593597

594-
open() {
598+
open(): Promise<unknown> | undefined {
595599
return this.toggle(true);
596600
}
597601

598-
close() {
602+
close(): Promise<unknown> | undefined {
599603
return this.toggle(false);
600604
}
601605

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,10 +961,10 @@ class Overlay<
961961

962962
_renderContentImpl(): Promise<void> {
963963
const whenContentRendered = Deferred();
964-
965964
const contentTemplateOption = this.option('contentTemplate');
966965
const contentTemplate = this._getTemplate(contentTemplateOption);
967966
const transclude = this._templateManager.anonymousTemplateName === contentTemplateOption;
967+
968968
contentTemplate?.render({
969969
container: getPublicElement(this.$content()),
970970
noModel: true,
@@ -978,6 +978,7 @@ class Overlay<
978978
}
979979
},
980980
});
981+
981982
const { preventScrollEvents } = this.option();
982983

983984
this._toggleWrapperScrollEventsSubscription(preventScrollEvents);
@@ -987,6 +988,7 @@ class Overlay<
987988
this._moveToContainer();
988989
}
989990
});
991+
990992
// @ts-expect-error ts-error
991993
return whenContentRendered.promise();
992994
}

packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/dropDownOptions.tests.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ const optionComparer = {
103103
assert.strictEqual(getPopupInstance(editor).option('position.of').get(0), expectedPosition.of.get(0), 'popup position.of is correct');
104104
},
105105
contentTemplate: function(assert, editor) {
106-
if(editor.NAME === 'dxDropDownBox' || editor.NAME === 'dxDropDownButton') {
106+
if(editor.NAME === 'dxDropDownBox') {
107107
assert.strictEqual(editor.option('dropDownOptions.contentTemplate'), 'content', 'dropDownOptions.contentTemplate is correct');
108108
assert.strictEqual(getPopupInstance(editor).option('contentTemplate'), 'content', 'popup contentTemplate is correct');
109109
return;
@@ -154,8 +154,10 @@ dropDownEditorsNames.forEach(widgetName => {
154154
QUnit.module('dropDownOptions on pure init', () => {
155155
dropDownOptionsKeys.forEach(option => {
156156
// TODO: fix this cases
157-
if(widgetName === 'dxDropDownBox' && (option === 'focusStateEnabled' || option === 'tabIndex')
158-
|| widgetName === 'dxDropDownButton' && (option === 'showCloseButton' || option === '_ignorePreventScrollEventsDeprecation')) {
157+
if(
158+
widgetName === 'dxDropDownBox' && (option === 'focusStateEnabled' || option === 'tabIndex')
159+
|| widgetName === 'dxDropDownButton' && (option === 'showCloseButton' || option === '_ignorePreventScrollEventsDeprecation')
160+
) {
159161
return;
160162
}
161163
QUnit.test(`${option} is correct`, function(assert) {

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2618,6 +2618,26 @@ QUnit.module('keyboard navigation', {
26182618
});
26192619
});
26202620

2621+
QUnit.module('content template', () => {
2622+
QUnit.test('content template render function should be called once (T1294338)', function(assert) {
2623+
const renderSpy = sinon.spy();
2624+
2625+
const dropDownButton = new DropDownButton($('#dropDownButton'), {
2626+
integrationOptions: {
2627+
templates: {
2628+
content: {
2629+
render: renderSpy,
2630+
},
2631+
},
2632+
},
2633+
});
2634+
2635+
dropDownButton.open();
2636+
2637+
assert.ok(renderSpy.calledOnce, 'render called once');
2638+
});
2639+
});
2640+
26212641
QUnit.module('custom content template', {}, () => {
26222642
QUnit.test('dropDownContentTemplate option can be used', function(assert) {
26232643
const templateHandler = sinon.stub().returns('Template 1');
@@ -2758,7 +2778,6 @@ QUnit.module('Button template', {}, () => {
27582778
});
27592779
});
27602780

2761-
27622781
QUnit.module('Accessibility', {
27632782
beforeEach: function() {
27642783
this.elementSelector = '#dropDownButton';

0 commit comments

Comments
 (0)