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 edd4d9c
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions components/lib/calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2286,26 +2286,36 @@ 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) {
console.log(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 edd4d9c

Please sign in to comment.