Skip to content

Commit 542cc5e

Browse files
marker-daomarker dao ®
andauthored
DateBox: Update time list items when value is changed while popup is closed (T1325614) (#33154)
Co-authored-by: marker dao ® <youdontknow@marker-dao.eth>
1 parent ba8d95b commit 542cc5e

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

packages/devextreme/js/__internal/ui/date_box/m_date_box.strategy.list.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,23 @@ class ListStrategy extends DateBoxStrategy {
130130
clearTimeout(this._asyncScrollTimeout);
131131
}
132132

133+
renderValue(): void {
134+
this._updateValue();
135+
}
136+
133137
_updateValue(): void {
134138
if (!this._widget) {
135139
return;
136140
}
137141

138142
this._refreshItems();
139143

140-
this._setSelectedItemsByValue();
141-
this._scrollToSelectedItem();
144+
const { opened } = this.dateBox.option();
145+
146+
if (opened) {
147+
this._setSelectedItemsByValue();
148+
this._scrollToSelectedItem();
149+
}
142150
}
143151

144152
_setSelectedItemsByValue(): void {

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

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2205,6 +2205,51 @@ QUnit.module('datebox w/ time list', {
22052205
assert.deepEqual(this.dateBox.option('value'), new Date(2020, 4, 13, 1, 30), 'date is correct');
22062206
});
22072207

2208+
QUnit.test('time selection should use updated date after external value change while popup is closed (T1325614)', function(assert) {
2209+
this.dateBox.option({
2210+
type: 'time',
2211+
pickerType: 'list',
2212+
value: new Date(1995, 11, 25, 12, 0),
2213+
opened: true
2214+
});
2215+
2216+
const $list = $(this.dateBox.content()).find(LIST_ITEM_SELECTOR);
2217+
2218+
$($list.eq(3)).trigger('dxclick');
2219+
2220+
this.dateBox.option('value', new Date(1995, 11, 12, 12, 0));
2221+
this.dateBox.open();
2222+
2223+
const $updatedList = $(this.dateBox.content()).find(LIST_ITEM_SELECTOR);
2224+
2225+
$($updatedList.eq(5)).trigger('dxclick');
2226+
2227+
const result = this.dateBox.option('value');
2228+
2229+
assert.strictEqual(result.getDate(), 12, 'date part is preserved after time selection');
2230+
assert.strictEqual(result.getMonth(), 11, 'month part is preserved after time selection');
2231+
assert.strictEqual(result.getFullYear(), 1995, 'year part is preserved after time selection');
2232+
});
2233+
2234+
QUnit.test('list items should be refreshed after value is changed while popup is closed (T1325614)', function(assert) {
2235+
this.dateBox.option({
2236+
type: 'time',
2237+
pickerType: 'list',
2238+
value: new Date(2020, 4, 13, 10, 0),
2239+
opened: true
2240+
});
2241+
2242+
this.dateBox.option('opened', false);
2243+
this.dateBox.option('value', new Date(2020, 8, 20, 10, 0));
2244+
this.dateBox.option('opened', true);
2245+
2246+
const itemData = this.dateBox._strategy._widgetItems[0];
2247+
2248+
assert.strictEqual(itemData.getFullYear(), 2020, 'item year is updated');
2249+
assert.strictEqual(itemData.getMonth(), 8, 'item month is updated');
2250+
assert.strictEqual(itemData.getDate(), 20, 'item day is updated');
2251+
});
2252+
22082253
QUnit.test('the date should be in range after the selection', function(assert) {
22092254
this.dateBox.option({
22102255
type: 'time',
@@ -2498,12 +2543,13 @@ QUnit.module('datebox w/ time list', {
24982543
dateSerializationFormat: 'yyyy-MM-ddTHH:mm:ssx',
24992544
});
25002545
const $input = $(this.dateBox.element()).find(`.${TEXTEDITOR_INPUT_CLASS}`);
2501-
const $items = $(this.dateBox.content()).find(LIST_ITEM_SELECTOR);
2546+
let $items = $(this.dateBox.content()).find(LIST_ITEM_SELECTOR);
25022547

25032548
$items.eq(1).trigger('dxclick');
25042549
assert.strictEqual($input.val(), $items.eq(1).text(), 'time is applied');
25052550

25062551
this.dateBox.open();
2552+
$items = $(this.dateBox.content()).find(LIST_ITEM_SELECTOR);
25072553
$items.eq(3).trigger('dxclick');
25082554
assert.strictEqual($input.val(), $items.eq(3).text(), 'new time is applied');
25092555
});

0 commit comments

Comments
 (0)