Skip to content

Commit

Permalink
fix: highlight range of month in datePicker (#6759)
Browse files Browse the repository at this point in the history
  • Loading branch information
KumJungMin committed Jun 14, 2024
1 parent d34e41c commit 8899b5f
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions components/lib/calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2328,17 +2328,29 @@ export const Calendar = React.memo(
};

const isMonthSelected = (month) => {
if (isComparable()) {
let value = isRangeSelection() ? props.value[0] : props.value;
if (!isComparable()) return false;

if (isMultipleSelection()) {
return value.some((currentValue) => currentValue.getMonth() === month && currentValue.getFullYear() === currentYear);
}
if (isMultipleSelection()) {
return props.value.some((v) => v.getMonth() === month && v.getFullYear() === currentYear);
} else if (isRangeSelection()) {
const [start, end] = props.value;
const startYear = start ? start.getFullYear() : null;
const endYear = end ? end.getFullYear() : null;
const startMonth = start ? start.getMonth() : null;
const endMonth = end ? end.getMonth() : null;

if (!end) {
return startYear === currentYear && startMonth === month;
} else {
const currentDate = new Date(currentYear, month, 1);
const startDate = new Date(startYear, startMonth, 1);
const endDate = new Date(endYear, endMonth, 1);

return value.getMonth() === month && value.getFullYear() === currentYear;
return currentDate >= startDate && currentDate <= endDate;
}
} else {
return props.value.getMonth() === month && props.value.getFullYear() === currentYear;
}

return false;
};

const isYearSelected = (year) => {
Expand Down

0 comments on commit 8899b5f

Please sign in to comment.