Skip to content

Commit

Permalink
Fix primefaces#5863: Calendar enabledDates evaluated last
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Jan 31, 2024
1 parent ad59eb0 commit 4ba6808
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions components/lib/calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2286,26 +2286,34 @@ 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) {
// possible re-enable already disabled date
if (props.enabledDates.some((d) => d.getFullYear() === year && d.getMonth() === month && d.getDate() === day)) {
isDisabled = !isDisabled;
}
}

return isDisabled;
};

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

0 comments on commit 4ba6808

Please sign in to comment.