Merge pull request #2590 from Ancient-Dragon/bugfix/#2588

Fix calendar selecting time when in range mode
pull/2593/head
Tuğçe Küçükoğlu 2022-05-31 14:07:59 +03:00 committed by GitHub
commit 0a0c77b426
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 5 deletions

View File

@ -42,4 +42,12 @@ describe('Calendar.vue', () => {
await wrapper.vm.onDateSelect({currentTarget: {focus: () => {}}}, event);
expect(onDateSelect).toHaveBeenCalled()
});
it('should calculate the correct view date when in range mode', async () => {
const dateOne = new Date();
const dateTwo = new Date();
dateTwo.setFullYear(dateOne.getFullYear(), dateOne.getMonth(), dateOne.getDate() + 1)
await wrapper.setProps({ selectionMode: 'range', showTime: true, modelValue: [dateOne, dateTwo] });
expect(wrapper.vm.viewDate).toEqual(dateTwo)
});
});

View File

@ -2288,13 +2288,16 @@ export default {
viewDate() {
let propValue = this.modelValue;
if (propValue && Array.isArray(propValue)) {
propValue = propValue[0];
if (this.isRangeSelection()) {
propValue = propValue[1] || propValue[0];
} else if (this.isMultipleSelection()) {
propValue = propValue[propValue.length - 1];
}
}
if (propValue && typeof propValue !== 'string') {
return propValue;
}
else {
} else {
let today = new Date();
if (this.maxDate && this.maxDate < today) {
return this.maxDate;