Skip to content

Commit a618947

Browse files
committed
fix(YearsView): navigate correctly in the years view #6275
1 parent ea169d1 commit a618947

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

Diff for: projects/igniteui-angular/src/lib/calendar/calendar.component.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,10 @@ export class IgxCalendarComponent extends IgxMonthPickerBaseDirective implements
489489
*/
490490
public nextMonth(isKeydownTrigger = false) {
491491
if (isKeydownTrigger && this.animationAction === 'prev') { return; }
492+
this.isKeydownTrigger = isKeydownTrigger;
492493
this.previousViewDate = this.viewDate;
493494
this.viewDate = this.calendarModel.getNextMonth(this.viewDate);
494495
this.animationAction = ScrollMonth.NEXT;
495-
this.isKeydownTrigger = isKeydownTrigger;
496496
}
497497

498498
/**
@@ -553,7 +553,7 @@ export class IgxCalendarComponent extends IgxMonthPickerBaseDirective implements
553553
requestAnimationFrame(() => {
554554
if (this.dacadeView) {
555555
this.dacadeView.date = args;
556-
this.dacadeView.el.nativeElement.focus();
556+
this.dacadeView.calendarDir.find(date => date.isCurrentYear).nativeElement.focus();
557557
}
558558
});
559559
}
@@ -568,7 +568,7 @@ export class IgxCalendarComponent extends IgxMonthPickerBaseDirective implements
568568
requestAnimationFrame(() => {
569569
if (this.dacadeView) {
570570
this.dacadeView.date = args;
571-
this.dacadeView.el.nativeElement.focus();
571+
this.dacadeView.calendarDir.find(date => date.isCurrentYear).nativeElement.focus();
572572
}
573573
});
574574
}
@@ -729,6 +729,9 @@ export class IgxCalendarComponent extends IgxMonthPickerBaseDirective implements
729729
(event.fromState === 'void' && event.toState === ScrollMonth.NONE)) {
730730
this.viewDateChanged.emit({ previousValue: this.previousViewDate, currentValue: this.viewDate });
731731
}
732+
if (!this.isKeydownTrigger) {
733+
this.resetActiveDate();
734+
}
732735

733736
if (this.monthScrollDirection !== ScrollMonth.NONE) {
734737
this.scrollMonth$.next();
@@ -753,7 +756,6 @@ export class IgxCalendarComponent extends IgxMonthPickerBaseDirective implements
753756
this.callback(this.nextDate);
754757
}
755758
this.animationAction = ScrollMonth.NONE;
756-
this.resetActiveDate();
757759
}
758760

759761
/**

Diff for: projects/igniteui-angular/src/lib/calendar/calendar.directives.ts

+6
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ export class IgxCalendarYearDirective {
5858
return this.date.getFullYear() === this.value.getFullYear();
5959
}
6060

61+
public get nativeElement() {
62+
return this.elementRef.nativeElement;
63+
}
64+
65+
constructor(public elementRef: ElementRef) {}
66+
6167
@HostListener('click')
6268
public onClick() {
6369
this.onYearSelection.emit(this.value);

Diff for: projects/igniteui-angular/src/lib/calendar/years-view/years-view.component.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { Component, Output, EventEmitter, Input, HostBinding, HostListener, ElementRef, Injectable} from '@angular/core';
1+
import { Component, Output, EventEmitter, Input, HostBinding, HostListener, ElementRef, Injectable, ViewChildren, QueryList} from '@angular/core';
22
import { range, Calendar } from '../calendar';
33
import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms';
44
import { HammerGestureConfig, HAMMER_GESTURE_CONFIG } from '@angular/platform-browser';
5+
import { IgxCalendarYearDirective } from '../calendar.directives';
56

67
let NEXT_ID = 0;
78

@@ -134,6 +135,13 @@ export class IgxYearsViewComponent implements ControlValueAccessor {
134135
@HostBinding('class.igx-calendar')
135136
public styleClass = true;
136137

138+
/**
139+
* @hidden
140+
* @internal
141+
*/
142+
@ViewChildren(IgxCalendarYearDirective, { read: IgxCalendarYearDirective })
143+
public calendarDir: QueryList<IgxCalendarYearDirective>;
144+
137145
/**
138146
* Returns an array of date objects which are then used to properly
139147
* render the years.
@@ -268,6 +276,7 @@ export class IgxYearsViewComponent implements ControlValueAccessor {
268276
event.stopPropagation();
269277

270278
this.generateYearRange(1);
279+
this.calendarDir.find(date => date.isCurrentYear).nativeElement.nextElementSibling.focus();
271280
}
272281

273282
/**
@@ -279,6 +288,7 @@ export class IgxYearsViewComponent implements ControlValueAccessor {
279288
event.stopPropagation();
280289

281290
this.generateYearRange(-1);
291+
this.calendarDir.find(date => date.isCurrentYear).nativeElement.previousElementSibling.focus();
282292
}
283293

284294
/**

0 commit comments

Comments
 (0)