Skip to content

Commit 9c155d7

Browse files
r-farkhutdinovRuslan Farkhutdinov
andauthored
DateBox: Clear search value after re-selecting all with mask (T1308916) (#31862)
Co-authored-by: Ruslan Farkhutdinov <[email protected]>
1 parent 5e903b6 commit 9c155d7

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,12 @@ class DateBoxMask extends DateBoxBase {
236236
}
237237
}
238238

239-
_processInputKey(key) {
240-
if (this._isAllSelected()) {
239+
_processInputKey(key: string): void {
240+
const hasMultipleParts = this._dateParts?.length > 1;
241+
242+
if (this._isAllSelected() && hasMultipleParts) {
241243
this._activePartIndex = 0;
244+
this._clearSearchValue();
242245
}
243246
this._setNewDateIfEmpty();
244247
// eslint-disable-next-line radix

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import devices from '__internal/core/m_devices';
1111
const { test, module } = QUnit;
1212

1313
const CLEAR_BUTTON_AREA_CLASS = 'dx-clear-button-area';
14+
const TEXT_EDITOR_INPUT_CLASS = 'dx-texteditor-input';
1415

1516
const DROP_EVENT_NAME = 'drop';
1617

@@ -1644,6 +1645,33 @@ module('Regression', () => {
16441645

16451646
instance.focus();
16461647
});
1648+
1649+
QUnit.test('mask for HH:mm should be reset after selecting all multiple times (T1308916)', function(assert) {
1650+
const $dateBox = $('#dateBox').dxDateBox({
1651+
value: new Date(2021, 9, 17, 16, 6),
1652+
displayFormat: 'HH:mm',
1653+
type: 'time',
1654+
useMaskBehavior: true,
1655+
});
1656+
1657+
const $input = $dateBox.find(`.${TEXT_EDITOR_INPUT_CLASS}`);
1658+
const keyboard = keyboardMock($input, true);
1659+
1660+
const { length } = $input.val();
1661+
1662+
keyboard
1663+
.focus()
1664+
.caret({ start: 0, end: length })
1665+
.type('1234');
1666+
1667+
assert.strictEqual($input.val(), '12:34', 'text is correct after typing "1234" over full selection');
1668+
1669+
keyboard
1670+
.caret({ start: 0, end: length })
1671+
.type('12');
1672+
1673+
assert.strictEqual($input.val(), '12:34', 'both digits go to hours and minutes stay unchanged');
1674+
});
16471675
});
16481676

16491677
module('Caret moving', setupModule, () => {

0 commit comments

Comments
 (0)