diff --git a/packages/components/calendar/Calendar.tsx b/packages/components/calendar/Calendar.tsx index 708e18b1d8..52cd84efce 100644 --- a/packages/components/calendar/Calendar.tsx +++ b/packages/components/calendar/Calendar.tsx @@ -192,14 +192,21 @@ const Calendar = forwardRef((props, ref) => { const isRangeValid = rangeFromTo && rangeFromTo.from && rangeFromTo.to; const checkMonthSelectorDisabled = (yearIn: number, monthIn: number): boolean => { if (isRangeValid) { + // 读取起止年份 const beginYear = dayjs(rangeFromTo.from).year(); const endYear = dayjs(rangeFromTo.to).year(); + // 读取起止月份 + const beginMon = parseInt(dayjs(rangeFromTo.from).format('M'), 10); + const endMon = parseInt(dayjs(rangeFromTo.to).format('M'), 10); + + if (beginYear === endYear) { + // 同一年内,禁用开始月份至结束月份之外的月份选项 + return monthIn < beginMon || monthIn > endMon; + } if (yearIn === beginYear) { - const beginMon = parseInt(dayjs(rangeFromTo.from).format('M'), 10); return monthIn < beginMon; } if (yearIn === endYear) { - const endMon = parseInt(dayjs(rangeFromTo.to).format('M'), 10); return monthIn > endMon; } } @@ -214,7 +221,7 @@ const Calendar = forwardRef((props, ref) => { for (let i = yearBegin; i <= yearEnd; i++) { yearList.push({ value: i, - disabled: checkMonthSelectorDisabled(i, month), + disabled: false, }); } // 月列表 @@ -225,7 +232,7 @@ const Calendar = forwardRef((props, ref) => { }); } return [yearList, monthList]; - }, [rangeFromTo, year, month]); + }, [rangeFromTo, year]); // mode为 'month' 时,构造日历列表 const dateList = useMemo(