Merge pull request #6415 from avramz/fix/datepicker-manual-input-year

#6347 fix: Datepicker -> Allow user to set year via input when view="year"
pull/6471/head
Tuğçe Küçükoğlu 2024-09-24 15:39:54 +03:00 committed by GitHub
commit 30c4d0ae66
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 0 deletions

View File

@ -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');
});
});

View File

@ -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("'")) {