Skip to content

Commit

Permalink
Calendar: week number click should not select dates disabled by min/m…
Browse files Browse the repository at this point in the history
…ax options (#25528)
  • Loading branch information
Zedwag authored Sep 5, 2023
1 parent 6e0a0a5 commit 5363935
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isDefined } from '../../core/utils/type';
import dateUtils from '../../core/utils/date';

class CalendarSelectionStrategy {
constructor(component) {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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',
Expand Down

0 comments on commit 5363935

Please sign in to comment.