Skip to content

Commit 9aba7a4

Browse files
shumuuugithub-actions[bot]tdesign-bot
authored
fix(calendar): fix the months can be selected are out of range when set the range in the same year (#6045)
* fix(calendar): 修复了当设定日历的range值为同一年内时,终止月份之后的月份选项没有正常禁用的问题 * chore: update common * chore: stash changelog [ci skip] --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: tdesign-bot <[email protected]>
1 parent a2ae4ee commit 9aba7a4

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

packages/components/calendar/calendar.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,19 @@ export default defineComponent({
6868
function checkMonthAndYearSelectedDisabled(year: number, month: number): boolean {
6969
let disabled = false;
7070
if (rangeFromTo.value && rangeFromTo.value.from && rangeFromTo.value.to) {
71+
// 读取起止年份
7172
const beginYear = dayjs(rangeFromTo.value.from).year();
7273
const endYear = dayjs(rangeFromTo.value.to).year();
73-
if (year === beginYear) {
74-
const beginMon = parseInt(dayjs(rangeFromTo.value.from).format('M'), 10);
74+
// 读取起止月份
75+
const beginMon = parseInt(dayjs(rangeFromTo.value.from).format('M'), 10);
76+
const endMon = parseInt(dayjs(rangeFromTo.value.to).format('M'), 10);
77+
78+
if (beginYear === endYear) {
79+
// 同一年内,禁用开始月份至结束月份之外的月份选项
80+
disabled = month < beginMon || month > endMon;
81+
} else if (year === beginYear) {
7582
disabled = month < beginMon;
7683
} else if (year === endYear) {
77-
const endMon = parseInt(dayjs(rangeFromTo.value.to).format('M'), 10);
7884
disabled = month > endMon;
7985
}
8086
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
pr_number: 6045
3+
contributor: shumuuu
4+
---
5+
6+
- fix(calendar): 修复了当设定日历的range值为同一年内时,终止月份之后的月份选项没有正常禁用的问题 @shumuuu ([#6045](https://github.com/Tencent/tdesign-vue-next/pull/6045))

0 commit comments

Comments
 (0)