Skip to content

Commit 02eafa8

Browse files
authored
DropDownEditor: Detach focus events before attaching new ones (T1238121)
1 parent 98b2a9d commit 02eafa8

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

packages/devextreme/js/__internal/ui/drop_down_editor/m_drop_down_editor.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ const DropDownEditor = TextBox.inherit({
216216
},
217217

218218
_render() {
219+
this._detachFocusEvents();
220+
219221
this.callBase();
220222

221223
this._renderOpenHandler();
@@ -291,7 +293,9 @@ const DropDownEditor = TextBox.inherit({
291293
_renderField() {
292294
const fieldTemplate = this._getFieldTemplate();
293295

294-
fieldTemplate && this._renderTemplatedField(fieldTemplate, this._fieldRenderData());
296+
if (fieldTemplate) {
297+
this._renderTemplatedField(fieldTemplate, this._fieldRenderData());
298+
}
295299
},
296300

297301
_renderPlaceholder() {

packages/devextreme/js/__internal/ui/text_box/m_text_editor.base.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,11 @@ const TextEditorBase = Editor.inherit({
184184
this._renderStylingMode();
185185
this._renderInputType();
186186
this._renderPlaceholder();
187-
188187
this._renderProps();
189188

190189
this.callBase();
191190

192191
this._renderValue();
193-
194192
this._renderLabel();
195193
},
196194

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,29 @@ QUnit.module('focus policy', () => {
457457
assert.ok($dropDownEditor.hasClass('dx-state-focused'), 'Widget is focused after click on clearButton');
458458
});
459459

460+
[
461+
{ eventName: 'onFocusIn', scenario: 'focus' },
462+
{ eventName: 'onFocusOut', scenario: 'blur ' },
463+
].forEach(({ eventName, scenario }) => {
464+
QUnit.test(`${eventName} should be called only once on component ${scenario} when fieldTemplate is specified (T1238121)`, function(assert) {
465+
const eventStub = sinon.stub();
466+
467+
const dropDownEditor = $('#dropDownEditorLazy').dxDropDownEditor({
468+
[eventName]: eventStub,
469+
fieldTemplate(_, container) {
470+
$('<div>').dxTextBox({
471+
readOnly: true,
472+
}).appendTo(container);
473+
},
474+
}).dxDropDownEditor('instance');
475+
476+
dropDownEditor.focus();
477+
dropDownEditor.blur();
478+
479+
assert.strictEqual(eventStub.callCount, 1, `${eventName} called once`);
480+
});
481+
});
482+
460483
QUnit.testInActiveWindow('input is focused by click on dropDownButton', function(assert) {
461484
const $dropDownEditor = $('#dropDownEditorLazy').dxDropDownEditor({
462485
focusStateEnabled: true

0 commit comments

Comments
 (0)