未验证 提交 3e0c08c1 编写于 作者: liu_zheng_wu's avatar liu_zheng_wu 提交者: GitHub

fix: 修复 calendar 组件中当 defaultValue 为空时,如果月份列表包含当月,则默认定位到当月 (#813)

上级 c7551194
......@@ -694,6 +694,18 @@ export const CalendarItem = React.forwardRef<
}
}
})
} else {
// 当 defaultValue 为空时,如果月份列表包含当月,则默认定位到当月
const currentYear = new Date().getFullYear()
const currentMonth = new Date().getMonth() + 1
const currentYearMonthIndex = state.monthsData.findIndex((item) => {
return (
+item.curData[0] === currentYear && +item.curData[1] === currentMonth
)
})
if (currentYearMonthIndex > -1) {
current = currentYearMonthIndex
}
}
setDefaultRange(monthsNum, current)
......
......@@ -693,6 +693,18 @@ export const CalendarItem = React.forwardRef<
}
}
})
} else {
// 当 defaultValue 为空时,如果月份列表包含当月,则默认定位到当月
const currentYear = new Date().getFullYear()
const currentMonth = new Date().getMonth() + 1
const currentYearMonthIndex = state.monthsData.findIndex((item) => {
return (
+item.curData[0] === currentYear && +item.curData[1] === currentMonth
)
})
if (currentYearMonthIndex > -1) {
current = currentYearMonthIndex
}
}
setDefaultRange(monthsNum, current)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册