Skip to content

Commit

Permalink
update handleClickMonthOrYear.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
uvarov-frontend committed Dec 17, 2024
1 parent 5f5d52f commit 5178a93
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@ const handleMultipleYearSelection = (self: Calendar, itemEl: HTMLElement) => {
const dateMin = getDate(self.context.dateMin);
const dateMax = getDate(self.context.dateMax);
const monthCount = self.context.displayMonthsCount - 1;
const { columnID } = getColumnID(self, 'year');

const isBeforeMinDate = self.context.selectedMonth < dateMin.getMonth() && selectedYear <= dateMin.getFullYear();
const isAfterMaxDate = self.context.selectedMonth > dateMax.getMonth() - monthCount && selectedYear >= dateMax.getFullYear();
const isAfterMaxDate = self.context.selectedMonth > dateMax.getMonth() - monthCount + columnID && selectedYear >= dateMax.getFullYear();
const isBeforeMinYear = selectedYear < dateMin.getFullYear();
const isAfterMaxYear = selectedYear > dateMax.getFullYear();

const newSelectedYear = isBeforeMinDate || isBeforeMinYear ? dateMin.getFullYear() : isAfterMaxDate || isAfterMaxYear ? dateMax.getFullYear() : selectedYear;
const newSelectedMonth =
isBeforeMinDate || isBeforeMinYear ? dateMin.getMonth() : isAfterMaxDate || isAfterMaxYear ? dateMax.getMonth() - monthCount : self.context.selectedMonth;
isBeforeMinDate || isBeforeMinYear
? dateMin.getMonth()
: isAfterMaxDate || isAfterMaxYear
? dateMax.getMonth() - monthCount + columnID
: self.context.selectedMonth;

setContext(self, 'selectedYear', newSelectedYear);
setContext(self, 'selectedMonth', newSelectedMonth as Range<12>);
Expand Down

0 comments on commit 5178a93

Please sign in to comment.