Skip to content

Commit 77c8731

Browse files
r-farkhutdinovRuslan Farkhutdinov
andauthored
DateBox: Preserve selected date part after focusout + focusin (T1318439) (#32166)
Co-authored-by: Ruslan Farkhutdinov <ruslan.farkhutdinov@devexpress.com>
1 parent ee2fbb8 commit 77c8731

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

packages/devextreme/js/__internal/ui/date_box/m_date_box.mask.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { fitIntoRange, inRange, sign } from '@js/core/utils/math';
1111
import {
1212
isDate, isDefined, isFunction, isString,
1313
} from '@js/core/utils/type';
14+
import type { DxEvent } from '@js/events';
1415
import type { Properties } from '@js/ui/date_box';
1516
import dateLocalization from '@ts/core/localization/date';
1617

@@ -661,18 +662,22 @@ class DateBoxMask extends DateBoxBase {
661662
}
662663
}
663664

664-
_enterHandler() {
665+
_enterHandler(): void {
665666
this._fireChangeEvent();
666-
this._selectNextPart(FORWARD);
667+
668+
if (this._useMaskBehavior() && this._isAllSelected()) {
669+
this._selectFirstPart();
670+
} else {
671+
this._selectNextPart(FORWARD);
672+
}
667673
}
668674

669-
_focusOutHandler(e) {
675+
_focusOutHandler(e: DxEvent): void {
670676
const shouldFireChangeEvent = this._useMaskBehavior() && !e.isDefaultPrevented();
671677

672678
if (shouldFireChangeEvent) {
673679
this._fireChangeEvent();
674680
super._focusOutHandler(e);
675-
this._selectFirstPart();
676681
} else {
677682
super._focusOutHandler(e);
678683
}

packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/datebox.mask.tests.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,6 +1866,24 @@ module('Caret moving', setupModule, () => {
18661866

18671867
assert.deepEqual(this.keyboard.caret(), allSelectedCaret, 'no date part is selected');
18681868
});
1869+
1870+
test('should keep active part after focus out and focus in (T1318439)', function(assert) {
1871+
const caretYear = { start: 11, end: 15 };
1872+
1873+
this.instance.option({
1874+
useMaskBehavior: true,
1875+
mode: 'text',
1876+
});
1877+
1878+
this.keyboard.press('end');
1879+
1880+
assert.deepEqual(this.keyboard.caret(), caretYear, 'year is selected initially');
1881+
1882+
this.$input.trigger('focusout');
1883+
this.$input.trigger('focusin');
1884+
1885+
assert.deepEqual(this.keyboard.caret(), caretYear, 'year is selected after focus return');
1886+
});
18691887
});
18701888

18711889
module('Using beforeInput event', {

0 commit comments

Comments
 (0)