diff --git a/packages/semi-foundation/datePicker/yearAndMonthFoundation.ts b/packages/semi-foundation/datePicker/yearAndMonthFoundation.ts index f5fb449dc8..78694f029d 100644 --- a/packages/semi-foundation/datePicker/yearAndMonthFoundation.ts +++ b/packages/semi-foundation/datePicker/yearAndMonthFoundation.ts @@ -105,9 +105,9 @@ export default class YearAndMonthFoundation extends BaseFoundation month[right]) { - month[right] = item.month + 1; + month[right] = item.month ; } this._adapter.setCurrentMonth(month); @@ -121,8 +121,19 @@ export default class YearAndMonthFoundation extends BaseFoundation month === currentMonth[panelType]); let validMonth: typeof months[number]; @@ -131,15 +142,24 @@ export default class YearAndMonthFoundation extends BaseFoundation !disabledDate(setMonth(currentDate, month - 1))); } - if (validMonth) { - const month = copy(currentMonth); - month[panelType] = validMonth.month; - - // change year and month same time - this._adapter.setCurrentYearAndMonth(year, month); - this._adapter.notifySelectYearAndMonth(year, month); + if (validMonth && !isOppositeMonthDisabled) { + // only currentPanel Date is illegal + // just need to modify the month of the current panel + finalMonth[panelType] = validMonth.month; + } else if (validMonth && isOppositeMonthDisabled) { + // all panel Date is illegal + // change the value to the legal value calculated by the current panel + finalYear = { 'left': item.year, 'right': item.year }; + finalMonth = { 'left': validMonth.month, 'right': validMonth.month }; } + } else if (!isCurrentMonthDisabled && isOppositeMonthDisabled) { + // only opposite panel Date is illegal + // change the value to the legal value in the current panel + finalYear = { 'left': item.year, 'right': item.year }; + finalMonth = { 'left': currentMonth[panelType], 'right': currentMonth[panelType] }; } + this._adapter.setCurrentYearAndMonth(finalYear, finalMonth); + this._adapter.notifySelectYearAndMonth(finalYear, finalMonth); } backToMain() { diff --git a/packages/semi-ui/datePicker/_story/datePicker.stories.jsx b/packages/semi-ui/datePicker/_story/datePicker.stories.jsx index 11e1a7f3b1..97466f6cda 100644 --- a/packages/semi-ui/datePicker/_story/datePicker.stories.jsx +++ b/packages/semi-ui/datePicker/_story/datePicker.stories.jsx @@ -605,6 +605,12 @@ export const MonthRangePicker = () => { return date.getTime() < deadDate.getTime(); }; + const disabledRangeDate = date => { + const deadDate = new Date('2025/3/1 00:00:00'); + const startDate = new Date('2024/11/1 00:00:00'); + return date.getTime() < startDate.getTime() || date.getTime() > deadDate.getTime(); + }; + return ( <>
@@ -640,6 +646,8 @@ export const MonthRangePicker = () => {
年月禁用:禁用2023年3月前的所有年月
+
年月禁用:禁用2024年11月前 & 2025年2月后的所有年月
+

validateStatus