Skip to content

Commit

Permalink
feat(calendar): fix next month selection fix when current month is de… (
Browse files Browse the repository at this point in the history
#963)

…cember
  • Loading branch information
dilandoogan authored Dec 4, 2024
1 parent 7b0ddd5 commit 23a3513
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/components/calendar/bl-calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ export default class BlCalendar extends DatepickerCalendarMixin {
setNextCalendarView() {
this.clearRangePickerStyles();
if (this._calendarView === CALENDAR_VIEWS.DAYS) {
this._calendarMonth === LAST_MONTH_INDEX
? ((this._calendarMonth = FIRST_MONTH_INDEX), (this._calendarYear += 1))
: (this._calendarMonth += 1);
if (this._calendarMonth === LAST_MONTH_INDEX) {
this._calendarMonth = FIRST_MONTH_INDEX;
this._calendarYear += 1;
} else this._calendarMonth += 1;
} else if (this._calendarView === CALENDAR_VIEWS.MONTHS) {
this._calendarYear += 1;
} else if (this._calendarView === CALENDAR_VIEWS.YEARS) {
Expand Down Expand Up @@ -135,8 +136,19 @@ export default class BlCalendar extends DatepickerCalendarMixin {

handleDate(date: Date) {
if (this.type !== CALENDAR_TYPES.RANGE) {
if (date.getMonth() < this._calendarMonth) this.setPreviousCalendarView();
else if (date.getMonth() > this._calendarMonth) this.setNextCalendarView();
const isDateBeforeThanCalendar =
date.getFullYear() < this._calendarYear ||
(date.getFullYear() === this._calendarYear && date.getMonth() < this._calendarMonth);

const isDateAfterThanCalendar =
date.getFullYear() > this._calendarYear ||
(date.getFullYear() === this._calendarYear && date.getMonth() > this._calendarMonth);

if (isDateBeforeThanCalendar) {
this.setPreviousCalendarView();
} else if (isDateAfterThanCalendar) {
this.setNextCalendarView();
}
}

switch (this.type) {
Expand Down

0 comments on commit 23a3513

Please sign in to comment.