fix(components): [date-picker] disabled year not selectable (#8414)

closed #8409
This commit is contained in:
LIUCHAO 2022-07-04 21:41:15 +08:00 committed by GitHub
parent e09c0dbc39
commit 9f42ce8694
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1482,4 +1482,38 @@ describe('MonthRange', () => {
expect(formItem.attributes().role).toBe('group')
})
})
it('The year which is disabled should not be selectable', async () => {
const pickHandler = vi.fn()
const wrapper = _mount(
`<el-date-picker
v-model="yearValue"
type="year"
:disabled-date="validateYear"
@panel-change="onPick"
/>`,
() => ({
yearValue: '2022',
validateYear: (date) => {
if (date.getFullYear() > 2022) {
return true
} else {
return false
}
},
onPick(e) {
return pickHandler(e)
},
})
)
const input = wrapper.find('input')
input.trigger('focus')
await nextTick()
;(document.querySelector('td.disabled') as HTMLElement).click()
await nextTick()
expect(pickHandler).toHaveBeenCalledTimes(0)
;(document.querySelector('td.available') as HTMLElement).click()
await nextTick()
expect(pickHandler).toHaveBeenCalledTimes(1)
})
})