From 7dca140cf3130f59c1ba83d8c8c161936d71f854 Mon Sep 17 00:00:00 2001 From: Alexander Kozlovskiy Date: Tue, 7 Nov 2023 13:28:25 -0600 Subject: [PATCH] pass onHover and onActive handlers as props --- .../js/ui/text_box/ui.text_editor.base.js | 2 + .../js/ui/text_box/ui.text_editor.label.js | 4 +- .../textEditorLabel.tests.js | 39 +++++++++++++------ 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/packages/devextreme/js/ui/text_box/ui.text_editor.base.js b/packages/devextreme/js/ui/text_box/ui.text_editor.base.js index cbb663b80037..38e4a77c986c 100644 --- a/packages/devextreme/js/ui/text_box/ui.text_editor.base.js +++ b/packages/devextreme/js/ui/text_box/ui.text_editor.base.js @@ -515,6 +515,8 @@ const TextEditorBase = Editor.inherit({ onClickHandler: () => { this.focus(); }, + onHoverHandler: (e) => { e.stopPropagation(); }, + onActiveHandler: (e) => { e.stopPropagation(); }, $editor: this.$element(), text: label, mark: labelMark, diff --git a/packages/devextreme/js/ui/text_box/ui.text_editor.label.js b/packages/devextreme/js/ui/text_box/ui.text_editor.label.js index 50bac6807138..5e5fd7477fd9 100644 --- a/packages/devextreme/js/ui/text_box/ui.text_editor.label.js +++ b/packages/devextreme/js/ui/text_box/ui.text_editor.label.js @@ -87,10 +87,10 @@ class TextEditorLabel { } }); eventsEngine.on(this._$labelSpan, hoverStartEventName, (e) => { - e.stopPropagation(); + this._props.onHoverHandler(); }); eventsEngine.on(this._$labelSpan, activeEventName, (e) => { - e.stopPropagation(); + this._props.onActiveHandler(); }); } } diff --git a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/textEditorLabel.tests.js b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/textEditorLabel.tests.js index 36398f9a405a..2f51fcf34980 100644 --- a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/textEditorLabel.tests.js +++ b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/textEditorLabel.tests.js @@ -97,19 +97,34 @@ QUnit.module('textEditorLabel', { QUnit.module('Outside labelMode', () => { ['init', 'runtime'].forEach((scenario) => { - QUnit.test(`onClickHandler should be called on label click when mode is set to "outside" on ${scenario}`, function(assert) { - const setOnInit = scenario === 'init'; - this.reinit({ - onClickHandler: this.spy, - mode: setOnInit ? 'outside' : 'static', - }); - - if(!setOnInit) { - this.label.updateMode('outside'); + [ + { + eventName: 'dxclick', + handlerName: 'onClickHandler', + }, + { + eventName: 'dxhoverstart', + handlerName: 'onHoverHandler', + }, + { + eventName: 'dxactive', + handlerName: 'onActiveHandler', } - $(this.getSpan()).trigger('dxclick'); - - assert.strictEqual(this.spy.callCount, 1, 'onClick handler was called on label click'); + ].forEach(({ eventName, handlerName }) => { + QUnit.test(`${handlerName} should be called on label ${eventName} when mode is set to "outside" on ${scenario}`, function(assert) { + const setOnInit = scenario === 'init'; + this.reinit({ + [handlerName]: this.spy, + mode: setOnInit ? 'outside' : 'static', + }); + + if(!setOnInit) { + this.label.updateMode('outside'); + } + $(this.getSpan()).trigger(eventName); + + assert.strictEqual(this.spy.callCount, 1, `${handlerName} was called`); + }); }); QUnit.test(`onClickHandler should not be called on label with empty text click when mode is set to "outside" on ${scenario}`, function(assert) {