diff --git a/packages/devextreme/js/__internal/ui/date_box/m_date_box.mask.ts b/packages/devextreme/js/__internal/ui/date_box/m_date_box.mask.ts index b1d5c78b4956..ced4a0def4c2 100644 --- a/packages/devextreme/js/__internal/ui/date_box/m_date_box.mask.ts +++ b/packages/devextreme/js/__internal/ui/date_box/m_date_box.mask.ts @@ -11,6 +11,7 @@ import { fitIntoRange, inRange, sign } from '@js/core/utils/math'; import { isDate, isDefined, isFunction, isString, } from '@js/core/utils/type'; +import type { DxEvent } from '@js/events'; import type { Properties } from '@js/ui/date_box'; import dateLocalization from '@ts/core/localization/date'; @@ -661,18 +662,22 @@ class DateBoxMask extends DateBoxBase { } } - _enterHandler() { + _enterHandler(): void { this._fireChangeEvent(); - this._selectNextPart(FORWARD); + + if (this._useMaskBehavior() && this._isAllSelected()) { + this._selectFirstPart(); + } else { + this._selectNextPart(FORWARD); + } } - _focusOutHandler(e) { + _focusOutHandler(e: DxEvent): void { const shouldFireChangeEvent = this._useMaskBehavior() && !e.isDefaultPrevented(); if (shouldFireChangeEvent) { this._fireChangeEvent(); super._focusOutHandler(e); - this._selectFirstPart(); } else { super._focusOutHandler(e); } diff --git a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/datebox.mask.tests.js b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/datebox.mask.tests.js index 2a1402895338..6cc12e77a1af 100644 --- a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/datebox.mask.tests.js +++ b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/datebox.mask.tests.js @@ -1866,6 +1866,24 @@ module('Caret moving', setupModule, () => { assert.deepEqual(this.keyboard.caret(), allSelectedCaret, 'no date part is selected'); }); + + test('should keep active part after focus out and focus in (T1318439)', function(assert) { + const caretYear = { start: 11, end: 15 }; + + this.instance.option({ + useMaskBehavior: true, + mode: 'text', + }); + + this.keyboard.press('end'); + + assert.deepEqual(this.keyboard.caret(), caretYear, 'year is selected initially'); + + this.$input.trigger('focusout'); + this.$input.trigger('focusin'); + + assert.deepEqual(this.keyboard.caret(), caretYear, 'year is selected after focus return'); + }); }); module('Using beforeInput event', {