Skip to content

Commit

Permalink
Calendar: it should not be possible to focus dates that are disabled …
Browse files Browse the repository at this point in the history
…using combination of disabledDates+min/max (#26279)
  • Loading branch information
Zedwag authored Dec 16, 2023
1 parent 7135895 commit 27f73ba
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
18 changes: 17 additions & 1 deletion packages/devextreme/js/ui/calendar/ui.calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,29 @@ const Calendar = Editor.inherit({
}

if(this._view.isDateDisabled(baseDate) || this._view.isDateDisabled(currentDate)) {
this._waitRenderView(offset > 0 ? 1 : -1);
const direction = offset > 0 ? 1 : -1;
const isViewDisabled = direction === 1 ? this._isNextViewDisabled() : this._isPrevViewDisabled();

if(!isViewDisabled) {
this._waitRenderView(direction);
} else {
this._moveToClosestAvailableDate(currentDate);
}

} else {
this._skipNavigate = true;
this.option('currentDate', currentDate);
}
},

_isNextViewDisabled() {
return this._navigator._nextButton.option('disabled');
},

_isPrevViewDisabled() {
return this._navigator._prevButton.option('disabled');
},

_areDatesInSameView(zoomLevel, date1, date2) {
switch(zoomLevel) {
case ZOOM_LEVEL.MONTH:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4091,6 +4091,32 @@ QUnit.module('disabledDates option', {

assert.deepEqual(this.calendar.option('currentDate'), new Date(2010, 10, 10), 'currentDate is the closest available date');
});

QUnit.test('It should not be possible to focus dates that are disabled using combination of disabledDates+min/max', function(assert) {
const calendar = this.calendar;

calendar.option({
value: new Date('2023/09/11'),
max: new Date('2023/09/16'),
min: new Date('2023/09/10'),
disabledDates: (d) => {
const day = d.date.getDay();

return d.view === 'month' && day === 0 || day === 6;
},
});
const $viewsWrapper = $(calendar._$viewsWrapper);

calendar.focus();

triggerKeydown($viewsWrapper, LEFT_ARROW_KEY_CODE);
assert.deepEqual(calendar.option('currentDate'), new Date('2023/09/11'), 'left disabledDate is not focused');

calendar.option('value', new Date('2023/09/15'));

triggerKeydown($viewsWrapper, RIGHT_ARROW_KEY_CODE);
assert.deepEqual(calendar.option('currentDate'), new Date('2023/09/15'), 'right disabledDate is not focused');
});
});


Expand Down Expand Up @@ -4184,7 +4210,6 @@ QUnit.module('Current date', {
iterateViews($.proxy((_, type) => {
this.reinit();

const $element = this.$element;
const calendar = this.$element.dxCalendar($.extend(
{},
{ zoomLevel: type, focusStateEnabled: true },
Expand Down

0 comments on commit 27f73ba

Please sign in to comment.