Skip to content

Commit ba5d3a9

Browse files
author
Ruslan Farkhutdinov
committed
Calendar: Should switch to the last date view in multiple & controlled mode (T1279950)
1 parent 24a55ba commit ba5d3a9

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

packages/devextreme/js/__internal/ui/calendar/m_calendar.multiple.selection.strategy.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ class CalendarMultiSelectionStrategy extends CalendarSelectionStrategy {
3939
}
4040

4141
getDefaultCurrentDate() {
42-
const dates = this.dateOption('value').filter((value) => value);
43-
return this._getLowestDateInArray(dates);
42+
const dates = this.dateOption('value').filter(Boolean);
43+
if (dates.length) {
44+
return dates[dates.length - 1];
45+
}
4446
}
4547

4648
restoreValue() {

packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/calendar.tests.js

+37-7
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,27 @@ QUnit.module('Preserve time component on value change', {
13831383

13841384
assert.deepEqual(calendar.option('value'), new Date(2015, 8, 2, 12, 57));
13851385
});
1386+
1387+
QUnit.test('should switch to the last date after setting option programmatically (T1279950)', function(assert) {
1388+
this.calendar.option({
1389+
selectionMode: 'multiple',
1390+
value: [new Date(2025, 1, 10), new Date(2025, 2, 10)],
1391+
});
1392+
1393+
const calendar = this.calendar;
1394+
1395+
assert.ok(
1396+
dateUtils.sameMonth(calendar.option('currentDate'), new Date(2025, 2, 10)),
1397+
'initially navigated to the last date'
1398+
);
1399+
1400+
calendar.option('value', [new Date(2025, 2, 10), new Date(2025, 4, 10), new Date(2025, 3, 10)]);
1401+
1402+
assert.ok(
1403+
dateUtils.sameMonth(calendar.option('currentDate'), new Date(2025, 3, 10)),
1404+
'switched to the last entered date'
1405+
);
1406+
});
13861407
});
13871408

13881409

@@ -2015,15 +2036,15 @@ QUnit.module('Options', {
20152036

20162037
[
20172038
{
2018-
value: [new Date('01/05/2023'), new Date('02/01/2023')],
2039+
value: [new Date('02/01/2023'), new Date('01/05/2023')],
20192040
type: 'dates'
20202041
},
20212042
{
2022-
value: ['01/05/2023', '02/01/2023'],
2043+
value: ['02/01/2023', '01/05/2023'],
20232044
type: 'strings'
20242045
},
20252046
{
2026-
value: [1672916400000, 1675249200000],
2047+
value: [1675249200000, 1672916400000],
20272048
type: 'numbers'
20282049
}
20292050
].forEach(({ value, type }) => {
@@ -2040,14 +2061,23 @@ QUnit.module('Options', {
20402061
});
20412062

20422063
QUnit.module('CurrentDate', {}, () => {
2043-
QUnit.test(`Should be equal to the lowest defined date in value on init (selectionMode=${selectionMode}`, function(assert) {
2064+
const isMultipleMode = selectionMode === 'multiple';
2065+
const currentDateRule = isMultipleMode ? 'latest entered' : 'lowest defined';
2066+
2067+
QUnit.test(`Should be equal to the ${currentDateRule} date in value on init (selectionMode=${selectionMode}`, function(assert) {
2068+
const initialValue = [null, new Date('01/15/2023'), new Date('02/01/2023')];
2069+
20442070
this.reinit({
2045-
value: [null, new Date('01/15/2023'), new Date('02/01/2023')],
2071+
value: initialValue,
20462072
selectionMode
20472073
});
20482074
const { currentDate, value } = this.calendar.option();
20492075

2050-
assert.deepEqual(currentDate, new Date(Math.min(...value.filter(value => value))));
2076+
if(isMultipleMode) {
2077+
assert.deepEqual(currentDate, initialValue[initialValue.length - 1]);
2078+
} else {
2079+
assert.deepEqual(currentDate, new Date(Math.min(...value.filter(value => value))));
2080+
}
20512081
});
20522082

20532083
QUnit.test(`Should be equal to the lowest date in value on runtime value change (selectionMode=${selectionMode}`, function(assert) {
@@ -2106,7 +2136,7 @@ QUnit.module('Options', {
21062136
});
21072137

21082138
QUnit.test('It should be possible to deselect already selected value by click', function(assert) {
2109-
const $cell = $(getCurrentViewInstance(this.calendar).$element().find('*[data-value="2023/01/15"]'));
2139+
const $cell = $(getCurrentViewInstance(this.calendar).$element().find('*[data-value="2023/02/01"]'));
21102140

21112141
$cell.trigger('dxclick');
21122142

0 commit comments

Comments
 (0)