fix: [el-calendar] selected wrong date when change the month/year (#5297)

This commit is contained in:
msidolphin 2022-01-11 14:29:06 +08:00 committed by GitHub
parent 2606778d30
commit 1f71d3c80c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 4 deletions

View File

@ -156,4 +156,21 @@ describe('Calendar.vue', () => {
expect((firstRow.firstElementChild as HTMLElement).innerHTML).toContain('3')
expect((firstRow.lastElementChild as HTMLElement).innerHTML).toContain('9')
})
it('click previous month or next month', async () => {
const wrapper = _mount(
`
<el-calendar v-model="value"></el-calendar>
`,
() => ({ value: new Date('2019-04-01') })
)
await nextTick()
const btns = wrapper.findAll('.el-button')
const prevBtn = btns.at(0)
const nextBtn = btns.at(2)
await prevBtn.trigger('click')
expect(wrapper.find('.is-selected').text()).toBe('1')
await nextBtn.trigger('click')
expect(wrapper.find('.is-selected').text()).toBe('1')
})
})

View File

@ -83,22 +83,22 @@ export default defineComponent({
const now = dayjs().locale(lang.value)
const prevMonthDayjs = computed(() => {
return date.value.subtract(1, 'month')
return date.value.subtract(1, 'month').date(1)
})
const curMonthDatePrefix = computed(() => {
return dayjs(date.value).locale(lang.value).format('YYYY-MM')
})
const nextMonthDayjs = computed(() => {
return date.value.add(1, 'month')
return date.value.add(1, 'month').date(1)
})
const prevYearDayjs = computed(() => {
return date.value.subtract(1, 'year')
return date.value.subtract(1, 'year').date(1)
})
const nextYearDayjs = computed(() => {
return date.value.add(1, 'year')
return date.value.add(1, 'year').date(1)
})
const i18nDate = computed(() => {