From 5363935d8725371d3eaed8c57227cc5c363f80e2 Mon Sep 17 00:00:00 2001 From: Alexander Kozlovskiy Date: Wed, 6 Sep 2023 00:43:30 +0400 Subject: [PATCH] Calendar: week number click should not select dates disabled by min/max options (#25528) --- .../ui.calendar.selection.strategy.js | 8 +++- .../calendar.tests.js | 39 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/packages/devextreme/js/ui/calendar/ui.calendar.selection.strategy.js b/packages/devextreme/js/ui/calendar/ui.calendar.selection.strategy.js index 6fdfffc7cdea..e5d814d3fb10 100644 --- a/packages/devextreme/js/ui/calendar/ui.calendar.selection.strategy.js +++ b/packages/devextreme/js/ui/calendar/ui.calendar.selection.strategy.js @@ -1,4 +1,5 @@ import { isDefined } from '../../core/utils/type'; +import dateUtils from '../../core/utils/date'; class CalendarSelectionStrategy { constructor(component) { @@ -45,7 +46,12 @@ class CalendarSelectionStrategy { } _isDateDisabled(date) { - return this.calendar._view.isDateDisabled(date); + const min = this.calendar._dateOption('min'); + const max = this.calendar._dateOption('max'); + const isLessThanMin = isDefined(min) && date < min && !dateUtils.sameDate(min, date); + const isBiggerThanMax = isDefined(max) && date > max && !dateUtils.sameDate(max, date); + + return this.calendar._view.isDateDisabled(date) || isLessThanMin || isBiggerThanMax; } _getLowestDateInArray(dates) { diff --git a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/calendar.tests.js b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/calendar.tests.js index 3767a4940921..ae960311c675 100644 --- a/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/calendar.tests.js +++ b/packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/calendar.tests.js @@ -2571,6 +2571,27 @@ QUnit.module('Options', { assert.deepEqual(value, expectedValue, 'no dates are selected'); }); + + QUnit.test(`Click on week number should not select dates that are less than min/bigger than max (selectionMode=${selectionMode})`, function(assert) { + const date = new Date('2023/09/05'); + this.reinit({ + selectionMode, + showWeekNumbers: true, + currentDate: date, + min: date, + max: date, + }); + + const $row = this.$element.find('tr').eq(2); + const $weekNumberCell = $row.find(`.${CALENDAR_WEEK_NUMBER_CELL_CLASS}`); + + $weekNumberCell.trigger('dxclick'); + + const value = this.calendar.option('value'); + const expectedValue = selectionMode === 'multiple' ? [date] : [date, date]; + + assert.deepEqual(value, expectedValue); + }); }); QUnit.test('Click on week number should not select disabled dates in multiple selectionMode', function(assert) { @@ -2590,6 +2611,24 @@ QUnit.module('Options', { assert.strictEqual(value.length, 1, 'only one day is selected'); }); + QUnit.test('Click on week number should select dates correctly when min/max=null (selectionMode=multiple)', function(assert) { + this.reinit({ + selectionMode: 'multiple', + showWeekNumbers: true, + min: null, + max: null, + }); + + const $row = this.$element.find('tr').eq(2); + const $weekNumberCell = $row.find(`.${CALENDAR_WEEK_NUMBER_CELL_CLASS}`); + + $weekNumberCell.trigger('dxclick'); + + const valueLength = this.calendar.option('value').length; + + assert.deepEqual(valueLength, 7, 'week is selected'); + }); + QUnit.test('Click on week number should select range from first available date to last available date', function(assert) { this.reinit({ selectionMode: 'range',