Skip to content

Commit

Permalink
Fix #5863: Calendar enabledDates evaluated last (#5864)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored Jan 31, 2024
1 parent 3b3adb9 commit 1b98405
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions components/lib/calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2286,26 +2286,33 @@ export const Calendar = React.memo(
};

const isDayDisabled = (day, month, year) => {
let isDisabled = false;

// first check for disabled dates
if (props.disabledDates) {
if (props.disabledDates.some((d) => d.getFullYear() === year && d.getMonth() === month && d.getDate() === day)) {
return true;
}
} else if (props.enabledDates) {
if (!props.enabledDates.some((d) => d.getFullYear() === year && d.getMonth() === month && d.getDate() === day)) {
return true;
isDisabled = true;
}
}

if (props.disabledDays && currentView === 'date') {
// next if not disabled then check for disabled days
if (!isDisabled && props.disabledDays && currentView === 'date') {
let weekday = new Date(year, month, day);
let weekdayNumber = weekday.getDay();

if (props.disabledDays.indexOf(weekdayNumber) !== -1) {
return true;
isDisabled = true;
}
}

return false;
// last check for enabled dates to force dates enabled
if (props.enabledDates) {
const isEnabled = props.enabledDates.some((d) => d.getFullYear() === year && d.getMonth() === month && d.getDate() === day);

isDisabled = isDisabled ? !isEnabled : isEnabled;
}

return isDisabled;
};

const isMonthYearDisabled = (month, year) => {
Expand Down

0 comments on commit 1b98405

Please sign in to comment.