Skip to content

Commit 48debd0

Browse files
committed
fix(IgxCalendar): should not throw an error when press pgDown/Up #8074
1 parent ff03182 commit 48debd0

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

projects/igniteui-angular/src/lib/calendar/calendar-multi-view.component.spec.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { TestBed, async, fakeAsync, tick } from '@angular/core/testing';
33
import { FormsModule } from '@angular/forms';
44
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
55
import { configureTestSuite } from '../test-utils/configure-suite';
6-
import { UIInteractions } from '../test-utils/ui-interactions.spec';
6+
import { UIInteractions, wait } from '../test-utils/ui-interactions.spec';
77
import { IgxCalendarComponent, IgxCalendarModule } from './public_api';
88
import { IgxDatePickerComponent, IgxDatePickerModule } from '../date-picker/date-picker.component';
99
import { DateRangeType } from '../core/dates';
@@ -752,9 +752,9 @@ describe('Multi-View Calendar - ', () => {
752752
expect(document.activeElement).toEqual(monthDates[10]);
753753
}));
754754

755-
it('Verify that months increment/decrement continuously on enter keydown', (fakeAsync(() => {
755+
it('Verify that months increment/decrement continuously on enter keydown', (async() => {
756756
calendar.monthsViewNumber = 2;
757-
tick(100);
757+
await wait(100);
758758
fixture.detectChanges();
759759
const dates = [new Date('2019-10-15'), new Date('2019-11-15'), new Date('2019-12-15'),
760760
new Date('2020-1-15'), new Date('2020-2-15'), new Date('2020-3-15'), new Date('2020-4-15')];
@@ -764,20 +764,21 @@ describe('Multi-View Calendar - ', () => {
764764
for (let i = 1; i < dates.length - 1; i++) {
765765
const arrowRight = HelperTestFunctions.getNexArrowElement(fixture);
766766
UIInteractions.triggerKeyDownEvtUponElem('Enter', arrowRight);
767-
tick(100);
767+
fixture.detectChanges();
768+
await wait(100);
768769
fixture.detectChanges();
769770

770771
HelperTestFunctions.verifyCalendarSubHeaders(fixture, [dates[i], dates[i + 1]]);
771772
}
772-
for (let index = dates.length - 2; index > 0; index--) {
773+
for (let index = dates.length - 2; index > 0; index--) {
773774
const arrowLeft = HelperTestFunctions.getPreviousArrowElement(fixture);
774775
UIInteractions.triggerKeyDownEvtUponElem('Enter', arrowLeft);
775-
tick(100);
776776
fixture.detectChanges();
777-
777+
await wait(200);
778+
fixture.detectChanges();
778779
HelperTestFunctions.verifyCalendarSubHeaders(fixture, [dates[index - 1], dates[index]]);
779780
}
780-
})));
781+
}));
781782

782783
it('Verify that months increment/decrement continuously on mouse down', (fakeAsync(() => {
783784
calendar.monthsViewNumber = 2;

projects/igniteui-angular/src/lib/calendar/calendar.component.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,21 +707,24 @@ describe('IgxCalendar - ', () => {
707707
});
708708
});
709709

710-
it('Calendar keyboard navigation - PageUp/PageDown', () => {
710+
it('Calendar keyboard navigation - PageUp/PageDown', fakeAsync(() => {
711711
const component = dom.query(By.css(HelperTestFunctions.CALENDAR_CSSCLASS));
712712

713713
UIInteractions.triggerKeyDownEvtUponElem('PageUp', component.nativeElement);
714714
fixture.detectChanges();
715+
tick(100);
715716
expect(calendar.viewDate.getMonth()).toEqual(4);
716717

717718
calendar.viewDate = new Date(2017, 5, 13);
718719
fixture.detectChanges();
719720
UIInteractions.triggerKeyDownEvtUponElem('PageDown', component.nativeElement);
720721
fixture.detectChanges();
722+
tick(100);
721723

722724
expect(calendar.viewDate.getMonth()).toEqual(6);
723725
UIInteractions.triggerKeyDownEvtUponElem('PageUp', component.nativeElement, true, false, true);
724726
fixture.detectChanges();
727+
tick(100);
725728

726729
expect(calendar.viewDate.getFullYear()).toEqual(2016);
727730

@@ -730,9 +733,10 @@ describe('IgxCalendar - ', () => {
730733

731734
UIInteractions.triggerKeyDownEvtUponElem('PageDown', component.nativeElement, true, false, true);
732735
fixture.detectChanges();
736+
tick(100);
733737

734738
expect(calendar.viewDate.getFullYear()).toEqual(2018);
735-
});
739+
}));
736740

737741
it('Calendar keyboard navigation - Home/End/Enter', () => {
738742
const component = dom.query(By.css(HelperTestFunctions.CALENDAR_CSSCLASS));

projects/igniteui-angular/src/lib/calendar/calendar.component.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,8 @@ export class IgxCalendarComponent extends IgxMonthPickerBaseDirective implements
466466
* @internal
467467
*/
468468
public previousMonth(isKeydownTrigger = false) {
469+
debugger;
470+
if (isKeydownTrigger && this.animationAction === ScrollMonth.NEXT) { return; }
469471
this.previousViewDate = this.viewDate;
470472
this.viewDate = this.calendarModel.getPrevMonth(this.viewDate);
471473
this.animationAction = ScrollMonth.PREV;
@@ -479,6 +481,7 @@ export class IgxCalendarComponent extends IgxMonthPickerBaseDirective implements
479481
* @internal
480482
*/
481483
public nextMonth(isKeydownTrigger = false) {
484+
if (isKeydownTrigger && this.animationAction === 'prev') { return; }
482485
this.previousViewDate = this.viewDate;
483486
this.viewDate = this.calendarModel.getNextMonth(this.viewDate);
484487
this.animationAction = ScrollMonth.NEXT;
@@ -493,7 +496,7 @@ export class IgxCalendarComponent extends IgxMonthPickerBaseDirective implements
493496
public startPrevMonthScroll = (isKeydownTrigger = false) => {
494497
this.startMonthScroll$.next();
495498
this.monthScrollDirection = ScrollMonth.PREV;
496-
499+
this.animationAction = ScrollMonth.PREV;
497500
this.previousMonth(isKeydownTrigger);
498501
}
499502

@@ -505,7 +508,7 @@ export class IgxCalendarComponent extends IgxMonthPickerBaseDirective implements
505508
public startNextMonthScroll = (isKeydownTrigger = false) => {
506509
this.startMonthScroll$.next();
507510
this.monthScrollDirection = ScrollMonth.NEXT;
508-
511+
this.animationAction = ScrollMonth.NEXT;
509512
this.nextMonth(isKeydownTrigger);
510513
}
511514

@@ -764,11 +767,11 @@ export class IgxCalendarComponent extends IgxMonthPickerBaseDirective implements
764767
@HostListener('keydown.pageup', ['$event'])
765768
public onKeydownPageDown(event: KeyboardEvent) {
766769
event.preventDefault();
767-
768770
if (this.activeView !== CalendarView.DEFAULT) {
769771
return;
770772
}
771773

774+
772775
const isPageDown = event.key === 'PageDown';
773776
const step = isPageDown ? 1 : -1;
774777
let monthView = this.daysView as IgxDaysViewComponent;
@@ -811,8 +814,10 @@ export class IgxCalendarComponent extends IgxMonthPickerBaseDirective implements
811814
};
812815
}
813816

814-
if (isPageDown) { this.nextMonth(true); } else {
815-
this.previousMonth(true);
817+
if (isPageDown) {
818+
event.repeat ? requestAnimationFrame(() => this.nextMonth(true)) : this.nextMonth(true);
819+
} else {
820+
event.repeat ? requestAnimationFrame(() => this.previousMonth(true)) : this.previousMonth(true);
816821
}
817822
}
818823

0 commit comments

Comments
 (0)