Skip to content

Commit

Permalink
Merge pull request #123 from uvarov-frontend/hotfix/jumpMonths_for_se…
Browse files Browse the repository at this point in the history
…lect_month

Hotfix/jumpMonths for select month
  • Loading branch information
uvarov-frontend authored Oct 2, 2023
2 parents 81dcc1e + 71d2019 commit c48f621
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions package/src/scripts/methods/createMonths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import showMonth from './showMonth';
import showYear from './showYear';

const createMonths = (self: IVanillaCalendar, target?: HTMLElement) => {
const selectedMonth = target?.dataset.calendarSelectedMonth ? Number(target?.dataset.calendarSelectedMonth) : self.selectedMonth;
const selectedMonth = target?.dataset.calendarSelectedMonth ? Number(target?.dataset.calendarSelectedMonth) : self.selectedMonth as number;
self.currentType = 'month';
createDOM(self, target);
showMonth(self);
Expand All @@ -15,6 +15,10 @@ const createMonths = (self: IVanillaCalendar, target?: HTMLElement) => {

if (self.settings.selection.month) monthsEl.classList.add(self.CSSClasses.monthsSelecting);

const activeMonthsID = self.jumpMonths > 1 ? self.locale.months
.map((_, i) => selectedMonth - self.jumpMonths * i)
.concat(self.locale.months.map((_, i) => selectedMonth + self.jumpMonths * i))
.filter((monthID) => monthID >= 0 && monthID <= 12) : Array.from(Array(12).keys());
const templateMonthEl = document.createElement('button');
templateMonthEl.type = 'button';
templateMonthEl.className = self.CSSClasses.monthsMonth;
Expand All @@ -26,11 +30,10 @@ const createMonths = (self: IVanillaCalendar, target?: HTMLElement) => {
if (i === selectedMonth) {
monthEl.classList.add(self.CSSClasses.monthsMonthSelected);
}
if (i < self.dateMin.getMonth() && self.selectedYear === self.dateMin.getFullYear()) {
monthEl.classList.add(self.CSSClasses.monthsMonthDisabled);
monthEl.tabIndex = -1;
}
if (i > self.dateMax.getMonth() && self.selectedYear === self.dateMax.getFullYear()) {

if ((i < self.dateMin.getMonth() && self.selectedYear === self.dateMin.getFullYear())
|| (i > self.dateMax.getMonth() && self.selectedYear === self.dateMax.getFullYear())
|| (i !== selectedMonth && !activeMonthsID.includes(i))) {
monthEl.classList.add(self.CSSClasses.monthsMonthDisabled);
monthEl.tabIndex = -1;
}
Expand Down

0 comments on commit c48f621

Please sign in to comment.