Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/jumpMonths for select month #123

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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