Skip to content

Commit a4264f3

Browse files
authored
DropDownButton: Remove content template from Popup integrationOptions (T1294338)
1 parent bcd1394 commit a4264f3

File tree

4 files changed

+39
-12
lines changed

4 files changed

+39
-12
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,12 @@ const DropDownButton = (Widget as any).inherit({
319319
this._popupContentId = `dx-${new Guid()}`;
320320
this.setAria('id', this._popupContentId, $content);
321321

322-
return template.render({
322+
const result = template.render({
323323
container: getPublicElement($content),
324324
model: this.option('items') || this._dataController.getDataSource(),
325325
});
326+
327+
return result;
326328
},
327329

328330
_popupOptions() {
@@ -356,6 +358,7 @@ const DropDownButton = (Widget as any).inherit({
356358
at: `${horizontalAlignment} bottom`,
357359
},
358360
_wrapperClassExternal: DROP_DOWN_EDITOR_OVERLAY_CLASS,
361+
contentTemplate: null,
359362
}, this._options.cache('dropDownOptions'), { visible: this.option('opened') });
360363
},
361364

@@ -524,19 +527,20 @@ const DropDownButton = (Widget as any).inherit({
524527
this.$element().toggleClass(DROP_DOWN_BUTTON_HAS_ARROW_CLASS, hasArrow);
525528
},
526529

527-
toggle(visible) {
530+
toggle(visible?: boolean): Promise<unknown> | undefined {
528531
if (!this._popup) {
529532
this._renderPopup();
530533
this._renderContent();
531534
}
532-
return this._popup.toggle(visible);
535+
536+
return this._popup?.toggle(visible);
533537
},
534538

535-
open() {
539+
open(): Promise<unknown> | undefined {
536540
return this.toggle(true);
537541
},
538542

539-
close() {
543+
close(): Promise<unknown> | undefined {
540544
return this.toggle(false);
541545
},
542546

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -864,11 +864,11 @@ const Overlay: typeof OverlayInstance = Widget.inherit({
864864

865865
_renderContentImpl() {
866866
const whenContentRendered = Deferred();
867-
868867
const contentTemplateOption = this.option('contentTemplate');
869868
const contentTemplate = this._getTemplate(contentTemplateOption);
870869
const transclude = this._templateManager.anonymousTemplateName === contentTemplateOption;
871-
contentTemplate && contentTemplate.render({
870+
871+
contentTemplate?.render({
872872
container: getPublicElement(this.$content()),
873873
noModel: true,
874874
transclude,
@@ -882,7 +882,9 @@ const Overlay: typeof OverlayInstance = Widget.inherit({
882882
},
883883
});
884884

885-
this._toggleWrapperScrollEventsSubscription(this.option('preventScrollEvents'));
885+
const { preventScrollEvents } = this.option();
886+
887+
this._toggleWrapperScrollEventsSubscription(preventScrollEvents);
886888

887889
whenContentRendered.done(() => {
888890
if (this.option('visible')) {

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)