diff --git a/packages/primevue/src/datepicker/DatePicker.spec.js b/packages/primevue/src/datepicker/DatePicker.spec.js index 3254d07c5..7d6b987a2 100644 --- a/packages/primevue/src/datepicker/DatePicker.spec.js +++ b/packages/primevue/src/datepicker/DatePicker.spec.js @@ -98,4 +98,24 @@ describe('DatePicker.vue', () => { expect(wrapper.find('.p-datepicker-other-month span').exists()).toBe(true); }); + + it('should correctly set the year when view="year" and value is set via the input', async () => { + const dateOne = new Date(); + const dateTwo = new Date(); + + dateTwo.setFullYear(1988, 5, 15); + + await wrapper.setProps({ view: 'year', dateFormat: 'yy', modelValue: dateOne }); + + const input = wrapper.find('.p-datepicker-input'); + + await input.trigger('focus'); + + expect(wrapper.find('.p-datepicker-decade').exists()).toBe(true); + expect(wrapper.find('.p-datepicker-decade').text()).toBe('2020 - 2029'); + + await wrapper.setProps({ modelValue: dateTwo }); + + 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 740dbc687..07d843579 100755 --- a/packages/primevue/src/datepicker/DatePicker.vue +++ b/packages/primevue/src/datepicker/DatePicker.vue @@ -1911,6 +1911,11 @@ export default { day = 1; } + if (this.currentView === 'year') { + day = 1; + month = 1; + } + for (iFormat = 0; iFormat < format.length; iFormat++) { if (literal) { if (format.charAt(iFormat) === "'" && !lookAhead("'")) {