mirror of
https://github.com/element-plus/element-plus.git
synced 2025-02-17 11:49:41 +08:00
fix(components): [calendar] fix range year bug (#7227)
This commit is contained in:
parent
d26fa73420
commit
8be7123c75
@ -158,4 +158,27 @@ describe('Calendar.vue', () => {
|
||||
await nextBtn?.trigger('click')
|
||||
expect(wrapper.find('.is-selected').text()).toBe('1')
|
||||
})
|
||||
|
||||
it('range two years', async () => {
|
||||
const wrapper = mount(() => (
|
||||
<Calendar
|
||||
range={[new Date(2022, 0, 1), new Date(2022, 0, 31)]}
|
||||
></Calendar>
|
||||
))
|
||||
const titleEl = wrapper.find('.el-calendar__title')
|
||||
expect(/2021.*December/.test(titleEl.element.innerHTML)).toBeTruthy()
|
||||
const dateTables = wrapper.element.querySelectorAll(
|
||||
'.el-calendar-table.is-range'
|
||||
)
|
||||
expect(dateTables.length).toBe(3)
|
||||
const rows = wrapper.element.querySelectorAll('.el-calendar-table__row')
|
||||
expect(rows.length).toBe(6)
|
||||
const cell = rows[rows.length - 1].firstElementChild as HTMLElement
|
||||
cell.click()
|
||||
|
||||
await nextTick()
|
||||
|
||||
expect(/2022.*January/.test(titleEl.element.innerHTML)).toBeTruthy()
|
||||
expect(cell?.classList.contains('is-selected')).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
@ -152,7 +152,10 @@ const calculateValidatedDateRange = (
|
||||
]
|
||||
}
|
||||
// Three consecutive months (compatible: 2021-01-30 to 2021-02-28)
|
||||
else if (firstMonth + 2 === lastMonth) {
|
||||
else if (
|
||||
firstMonth + 2 === lastMonth ||
|
||||
(firstMonth + 1) % 11 === lastMonth
|
||||
) {
|
||||
const firstMonthLastDay = firstDay.endOf('month')
|
||||
const secondMonthFirstDay = firstDay.add(1, 'month').startOf('month')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user