Skip to content

Commit 4f39aa4

Browse files
fix(ui5-date-picker): Updating navigation buttons states live in mont… (#2307)
* fix(ui5-date-picker): Updating navigation buttons states live in month and year picker * lint fixes
1 parent 1fbb4f5 commit 4f39aa4

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

packages/main/src/Calendar.js

+33-8
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,7 @@ class Calendar extends UI5Element {
236236

237237
onBeforeRendering() {
238238
const oYearFormat = DateFormat.getDateInstance({ format: "y", calendarType: this._primaryCalendarType });
239-
const minDateParsed = this.minDate && this.getFormat().parse(this.minDate);
240-
const maxDateParsed = this.maxDate && this.getFormat().parse(this.maxDate);
241239
const firstDayOfCalendarTimeStamp = this._getMinCalendarDate();
242-
let currentMonth = 0;
243-
let currentYear = 1;
244240

245241
if ((this.minDate || this.maxDate) && this._timestamp && !this.isInValidRange(this._timestamp * 1000)) {
246242
if (this._minDate) {
@@ -258,8 +254,6 @@ class Calendar extends UI5Element {
258254
this._oMonth.maxDate = this.maxDate;
259255
this._header.monthText = this._oLocaleData.getMonths("wide", this._primaryCalendarType)[this._month];
260256
this._header.yearText = oYearFormat.format(this._localDate, true);
261-
currentMonth = this.timestamp && CalendarDate.fromTimestamp(this.timestamp * 1000).getMonth();
262-
currentYear = this.timestamp && CalendarDate.fromTimestamp(this.timestamp * 1000).getYear();
263257

264258
// month picker
265259
this._monthPicker.primaryCalendarType = this._primaryCalendarType;
@@ -274,6 +268,18 @@ class Calendar extends UI5Element {
274268

275269
this._isShiftingYears = false;
276270

271+
this._refreshNavigationButtonsState();
272+
}
273+
274+
_refreshNavigationButtonsState() {
275+
const minDateParsed = this.minDate && this.getFormat().parse(this.minDate);
276+
const maxDateParsed = this.maxDate && this.getFormat().parse(this.maxDate);
277+
let currentMonth = 0;
278+
let currentYear = 1;
279+
280+
currentMonth = this.timestamp && CalendarDate.fromTimestamp(this.timestamp * 1000).getMonth();
281+
currentYear = this.timestamp && CalendarDate.fromTimestamp(this.timestamp * 1000).getYear();
282+
277283
if (!this._oMonth._hidden) {
278284
if (this.minDate
279285
&& minDateParsed.getMonth() === currentMonth
@@ -292,17 +298,36 @@ class Calendar extends UI5Element {
292298
}
293299
}
294300

301+
if (!this._monthPicker._hidden) {
302+
if (this.minDate
303+
&& currentYear === minDateParsed.getFullYear()) {
304+
this._header._isPrevButtonDisabled = true;
305+
} else {
306+
this._header._isPrevButtonDisabled = false;
307+
}
308+
309+
if (this.maxDate
310+
&& currentYear === maxDateParsed.getFullYear()) {
311+
this._header._isNextButtonDisabled = true;
312+
} else {
313+
this._header._isNextButtonDisabled = false;
314+
}
315+
}
316+
295317
if (!this._yearPicker._hidden) {
318+
const cellsFromTheStart = 7;
319+
const cellsToTheEnd = 12;
320+
296321
currentYear = this._yearPicker.timestamp && CalendarDate.fromTimestamp(this._yearPicker.timestamp * 1000).getYear();
297322
if (this.minDate
298-
&& (currentYear - minDateParsed.getFullYear()) < 1) {
323+
&& (currentYear - minDateParsed.getFullYear()) < cellsFromTheStart) {
299324
this._header._isPrevButtonDisabled = true;
300325
} else {
301326
this._header._isPrevButtonDisabled = false;
302327
}
303328

304329
if (this.maxDate
305-
&& (maxDateParsed.getFullYear() - currentYear) < 1) {
330+
&& (maxDateParsed.getFullYear() - currentYear) < cellsToTheEnd) {
306331
this._header._isNextButtonDisabled = true;
307332
} else {
308333
this._header._isNextButtonDisabled = false;

packages/main/src/DayPicker.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,9 @@ class DayPicker extends UI5Element {
263263
let weekday;
264264
const _monthsNameWide = this._oLocaleData.getMonths("wide", this._calendarDate._oUDate.sCalendarType);
265265

266-
if (this.minDate) {
267-
this._minDateObject = new Date(this._minDate);
268-
}
266+
this._minDateObject = new Date(this._minDate);
267+
this._maxDateObject = new Date(this._maxDate);
269268

270-
if (this.maxDate) {
271-
this._maxDateObject = new Date(this._maxDate);
272-
}
273269
/* eslint-disable no-loop-func */
274270
for (let i = 0; i < _aVisibleDays.length; i++) {
275271
oCalDate = _aVisibleDays[i];
@@ -816,8 +812,12 @@ class DayPicker extends UI5Element {
816812
const maxDate = this._maxDateObject;
817813

818814
currentDate.setHours(0);
819-
minDate.setHours(0);
820-
maxDate.setHours(0);
815+
if (minDate) {
816+
minDate.setHours(0);
817+
}
818+
if (maxDate) {
819+
maxDate.setHours(0);
820+
}
821821

822822
return currentDate > maxDate || currentDate < minDate;
823823
}

0 commit comments

Comments
 (0)