Skip to content

Commit

Permalink
Merge pull request #213 from uvarov-frontend/bugfix/206_disable_all_days
Browse files Browse the repository at this point in the history
Bugfix/206_disable_all_days
  • Loading branch information
uvarov-frontend authored Feb 17, 2024
2 parents 4fa0587 + ee0acf4 commit b5a75b1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 7 additions & 3 deletions package/src/scripts/helpers/setVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@ const initRange = (self: VanillaCalendar) => {
self.rangeMin = isDisablePast
? getDateString(self.date.today)
: self.settings.range.disableAllDays
? getDateString(new Date(self.selectedYear, self.selectedMonth, 1))
? getDateString(self.date.today)
: self.settings.range.min;
self.rangeMax = self.settings.range.disableAllDays
? getDateString(new Date(self.selectedYear, self.selectedMonth, 1))
? getDateString(self.date.today)
: self.settings.range.max;

// set self.rangeDisabled
self.rangeDisabled = self.settings.range.disabled && !self.settings.range.disableAllDays ? parseDates(self.settings.range.disabled) : [];
self.rangeDisabled = self.settings.range.disabled && !self.settings.range.disableAllDays
? parseDates(self.settings.range.disabled)
: self.settings.range.disableAllDays
? [self.rangeMin]
: [];
if (self.rangeDisabled.length > 1) self.rangeDisabled.sort((a, b) => +new Date(a) - +new Date(b));

// set self.rangeEnabled
Expand Down
6 changes: 2 additions & 4 deletions package/src/scripts/methods/createDays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import createWeekNumbers from '@scripts/methods/createWeekNumbers';

const setDisabledDays = (self: VanillaCalendar, date: FormatDateString, dayWeekID: number) => {
const isDisableWeekday = self.settings.range.disableWeekday?.includes(dayWeekID);
const isDisableAllDays = self.settings.range.disableAllDays && self.rangeEnabled?.[0];
const isDisableAllDaysAndIsRangeEnabled = self.settings.range.disableAllDays && !!self.rangeEnabled?.[0];

if ((isDisableWeekday || isDisableAllDays) && !self.rangeEnabled?.includes(date) && !self.rangeDisabled?.includes(date)) {
if ((isDisableWeekday || isDisableAllDaysAndIsRangeEnabled) && !self.rangeEnabled?.includes(date) && !self.rangeDisabled?.includes(date)) {
self.rangeDisabled.push(date);
self.rangeDisabled?.sort((a, b) => +new Date(a) - +new Date(b));
}
Expand Down Expand Up @@ -149,8 +149,6 @@ const createDays = (self: VanillaCalendar) => {
const weekNumbersEls: NodeListOf<HTMLElement> = self.HTMLElement.querySelectorAll(`.${self.CSSClasses.weekNumbers}`);
const initDate = new Date(self.selectedYear as number, self.selectedMonth as number, 1);

if ((self.settings.range.disableAllDays || self.settings.range.disableWeekday) && self.rangeDisabled[0]) self.rangeDisabled = [];

daysEls.forEach((daysEl, index: number) => {
const selectedDate = new Date(initDate);
selectedDate.setMonth(selectedDate.getMonth() + index);
Expand Down

0 comments on commit b5a75b1

Please sign in to comment.