From e038ecd340be9e62c68fa1bafc8c87f38f083e65 Mon Sep 17 00:00:00 2001 From: Uros Date: Wed, 21 Aug 2024 10:21:09 +0200 Subject: [PATCH] #6203 fix: switching to year view when modelValue is populated (#6204) * #6203 fix: switching to year view when modelValue is populated * - remove debug --- .../src/datepicker/DatePicker.spec.js | 22 +++++++++++++++++++ .../primevue/src/datepicker/DatePicker.vue | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/primevue/src/datepicker/DatePicker.spec.js b/packages/primevue/src/datepicker/DatePicker.spec.js index 901546fdd0..8543ccb565 100644 --- a/packages/primevue/src/datepicker/DatePicker.spec.js +++ b/packages/primevue/src/datepicker/DatePicker.spec.js @@ -54,4 +54,26 @@ describe('DatePicker.vue', () => { expect(wrapper.vm.viewDate).toEqual(dateTwo); }); + + it('should open a year view when there is selected date (fix: #6203)', async () => { + const dateOne = new Date(); + + dateOne.setFullYear(1988, 9, 10); + + await wrapper.setProps({ modelValue: dateOne }); + + const input = wrapper.find('.p-datepicker-input'); + + await input.trigger('focus'); + + const yearSelectButton = wrapper.find('.p-datepicker .p-datepicker-select-year'); + + expect(yearSelectButton.exists()).toBe(true); + expect(yearSelectButton.text()).toBe('1988'); + + await yearSelectButton.trigger('click'); + + expect(wrapper.find('.p-datepicker-decade').exists()).toBe(true); + expect(wrapper.find('.p-datepicker-decade').text()).toBe('1980 - 1989'); + }); }); diff --git a/packages/primevue/src/datepicker/DatePicker.vue b/packages/primevue/src/datepicker/DatePicker.vue index 7c46091668..b7bab901c4 100755 --- a/packages/primevue/src/datepicker/DatePicker.vue +++ b/packages/primevue/src/datepicker/DatePicker.vue @@ -750,7 +750,7 @@ export default { return start === year || end === year || (start < year && end > year); } else { - return value.getFullYear() === year; + return this.modelValue.getFullYear() === year; } }, isDateEquals(value, dateMeta) {