diff --git a/projects/igniteui-angular/src/lib/calendar/calendar.component.html b/projects/igniteui-angular/src/lib/calendar/calendar.component.html index b70553e0022..4b04606c778 100644 --- a/projects/igniteui-angular/src/lib/calendar/calendar.component.html +++ b/projects/igniteui-angular/src/lib/calendar/calendar.component.html @@ -51,7 +51,7 @@

-
+
{{ formattedMonth(month) | titlecase }}
@@ -59,7 +59,7 @@

- + {{ formattedYear(year) }}
diff --git a/projects/igniteui-angular/src/lib/calendar/calendar.component.ts b/projects/igniteui-angular/src/lib/calendar/calendar.component.ts index 8e9648a6297..3dff2869d87 100644 --- a/projects/igniteui-angular/src/lib/calendar/calendar.component.ts +++ b/projects/igniteui-angular/src/lib/calendar/calendar.component.ts @@ -1153,6 +1153,20 @@ export class IgxCalendarComponent implements OnInit, ControlValueAccessor { return `${item.date.getMonth()}--${item.date.getDate()}`; } + /** + * @hidden + */ + public monthTracker(index, item): string { + return `${item.getMonth()}}`; + } + + /** + * @hidden + */ + public yearTracker(index, item): string { + return `${item.getFullYear()}}`; + } + /** * @hidden */ diff --git a/projects/igniteui-angular/src/lib/date-picker/date-picker.component.spec.ts b/projects/igniteui-angular/src/lib/date-picker/date-picker.component.spec.ts index cc318ee9e8b..77f2d0f5119 100644 --- a/projects/igniteui-angular/src/lib/date-picker/date-picker.component.spec.ts +++ b/projects/igniteui-angular/src/lib/date-picker/date-picker.component.spec.ts @@ -349,6 +349,54 @@ describe('IgxDatePicker', () => { expect(document.activeElement).toEqual(todayDate.nativeElement); }); + fit('#3595 - Should be able to change year', fakeAsync(() => { + const fix = TestBed.createComponent(IgxDatePickerTestComponent); + fix.detectChanges(); + + const target = fix.debugElement.query(By.css('.igx-icon')); + target.nativeElement.dispatchEvent(new Event('click')); + tick(); + fix.detectChanges(); + + let year = fix.debugElement.nativeElement.getElementsByClassName('igx-calendar-picker__date')[1]; + year.dispatchEvent(new Event('click')); + tick(); + fix.detectChanges(); + + const firstYear = fix.debugElement.query(By.css('.igx-calendar__year')); + const expectedResult = firstYear.nativeElement.innerText; + firstYear.nativeElement.dispatchEvent(new Event('click')); + tick(); + fix.detectChanges(); + + year = fix.debugElement.nativeElement.getElementsByClassName('igx-calendar-picker__date')[1]; + expect(year.innerText).toBe(expectedResult); + })); + + fit('#3595 - Should be able to change month', fakeAsync(() => { + const fix = TestBed.createComponent(IgxDatePickerTestComponent); + fix.detectChanges(); + + const target = fix.debugElement.query(By.css('.igx-icon')); + target.nativeElement.dispatchEvent(new Event('click')); + tick(); + fix.detectChanges(); + + let month = fix.debugElement.query(By.css('.igx-calendar-picker__date')); + month.nativeElement.dispatchEvent(new Event('click')); + tick(); + fix.detectChanges(); + + const firstMonth = fix.debugElement.query(By.css('.igx-calendar__month')); + const expectedResult = firstMonth.nativeElement.innerText; + firstMonth.nativeElement.dispatchEvent(new Event('click')); + tick(); + fix.detectChanges(); + + month = fix.debugElement.query(By.css('.igx-calendar-picker__date')); + expect(month.nativeElement.innerText).toBe(expectedResult); + })); + describe('EditorProvider', () => { it('Should return correct edit element', () => { const fixture = TestBed.createComponent(IgxDatePickerTestComponent);