Skip to content
Open
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/components/calendar/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,21 @@
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;
}
}
Expand All @@ -214,7 +221,7 @@
for (let i = yearBegin; i <= yearEnd; i++) {
yearList.push({
value: i,
disabled: checkMonthSelectorDisabled(i, month),
disabled: false,
});
}
// 月列表
Expand All @@ -225,7 +232,7 @@
});
}
return [yearList, monthList];
}, [rangeFromTo, year, month]);

Check warning on line 235 in packages/components/calendar/Calendar.tsx

View workflow job for this annotation

GitHub Actions / test

React Hook useMemo has an unnecessary dependency: 'month'. Either exclude it or remove the dependency array

// mode为 'month' 时,构造日历列表
const dateList = useMemo<CalendarCell[][]>(
Expand Down
Loading