Skip to content

Commit

Permalink
DropDownEditor: Detach focus events before attaching new ones (T1238121)
Browse files Browse the repository at this point in the history
  • Loading branch information
marker-dao authored Dec 17, 2024
1 parent 98b2a9d commit 02eafa8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ const DropDownEditor = TextBox.inherit({
},

_render() {
this._detachFocusEvents();

this.callBase();

this._renderOpenHandler();
Expand Down Expand Up @@ -291,7 +293,9 @@ const DropDownEditor = TextBox.inherit({
_renderField() {
const fieldTemplate = this._getFieldTemplate();

fieldTemplate && this._renderTemplatedField(fieldTemplate, this._fieldRenderData());
if (fieldTemplate) {
this._renderTemplatedField(fieldTemplate, this._fieldRenderData());
}
},

_renderPlaceholder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,11 @@ const TextEditorBase = Editor.inherit({
this._renderStylingMode();
this._renderInputType();
this._renderPlaceholder();

this._renderProps();

this.callBase();

this._renderValue();

this._renderLabel();
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,29 @@ QUnit.module('focus policy', () => {
assert.ok($dropDownEditor.hasClass('dx-state-focused'), 'Widget is focused after click on clearButton');
});

[
{ eventName: 'onFocusIn', scenario: 'focus' },
{ eventName: 'onFocusOut', scenario: 'blur ' },
].forEach(({ eventName, scenario }) => {
QUnit.test(`${eventName} should be called only once on component ${scenario} when fieldTemplate is specified (T1238121)`, function(assert) {
const eventStub = sinon.stub();

const dropDownEditor = $('#dropDownEditorLazy').dxDropDownEditor({
[eventName]: eventStub,
fieldTemplate(_, container) {
$('<div>').dxTextBox({
readOnly: true,
}).appendTo(container);
},
}).dxDropDownEditor('instance');

dropDownEditor.focus();
dropDownEditor.blur();

assert.strictEqual(eventStub.callCount, 1, `${eventName} called once`);
});
});

QUnit.testInActiveWindow('input is focused by click on dropDownButton', function(assert) {
const $dropDownEditor = $('#dropDownEditorLazy').dxDropDownEditor({
focusStateEnabled: true
Expand Down

0 comments on commit 02eafa8

Please sign in to comment.