From 1b9840556addbca3e1df363246091e89bf84a600 Mon Sep 17 00:00:00 2001 From: Melloware Date: Wed, 31 Jan 2024 10:58:00 -0500 Subject: [PATCH] Fix #5863: Calendar enabledDates evaluated last (#5864) --- components/lib/calendar/Calendar.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/components/lib/calendar/Calendar.js b/components/lib/calendar/Calendar.js index f6fe9fe076..d2ef974fc5 100644 --- a/components/lib/calendar/Calendar.js +++ b/components/lib/calendar/Calendar.js @@ -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) => {