Skip to content

Commit 5a5ddfe

Browse files
committed
feat(*): reset tab Index when navigationg out of the calendar #6275
1 parent ab5ada7 commit 5a5ddfe

File tree

8 files changed

+81
-11
lines changed

8 files changed

+81
-11
lines changed

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

+8
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ export class IgxCalendarBaseDirective implements ControlValueAccessor {
177177
public set viewDate(value: Date) {
178178
const date = this.getDateOnly(value).setDate(1);
179179
this._viewDate = new Date(date);
180+
this.resetActiveDate();
180181
}
181182

182183
/**
@@ -650,6 +651,7 @@ export class IgxCalendarBaseDirective implements ControlValueAccessor {
650651
this.selectRange(value, true);
651652
break;
652653
}
654+
this.resetActiveDate();
653655
}
654656

655657
/**
@@ -694,4 +696,10 @@ export class IgxCalendarBaseDirective implements ControlValueAccessor {
694696
break;
695697
}
696698
}
699+
700+
/**
701+
* @hidden
702+
* @internal
703+
*/
704+
public resetActiveDate() {}
697705
}

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ <h2 class="igx-calendar__header-date">
4545

4646
<div style="display: flex"
4747
[@animateChange]="animationAction"
48-
(@animateChange.done)="animationDone($event)">
48+
(@animateChange.done)="animationDone($event)" (focusout)="resetActiveDate()">
4949
<igx-days-view *ngFor="let view of monthsViewNumber | IgxMonthViewSlots; index as i;" [changeDaysView]="true" #days
5050
[selection]="selection"
5151
[locale]="locale"
5252
[value]="value"
53+
[activeDate]="activeDate"
5354
[viewDate]="i | IgxGetViewDate:viewDate"
5455
[weekStart]="weekStart"
5556
[formatOptions]="formatOptions"
@@ -59,7 +60,8 @@ <h2 class="igx-calendar__header-date">
5960
[hideOutsideDays]="hideOutsideDays"
6061
[showWeekNumbers]="showWeekNumbers"
6162
(onViewChanging)="viewChanging($event)"
62-
(onDateSelection)="childClicked($event)">
63+
(onDateSelection)="childClicked($event)"
64+
(activeDateChange)="activeDate = $event">
6365
</igx-days-view>
6466
</div>
6567
</div>

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

+20
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,12 @@ export class IgxCalendarComponent extends IgxMonthPickerBaseDirective implements
402402
return this.selectedDates ? this.selectedDates : new Date();
403403
}
404404

405+
/**
406+
* @hidden
407+
* @internal
408+
*/
409+
public activeDate = new Date().toLocaleDateString();
410+
405411
/**
406412
* @hidden
407413
* @internal
@@ -768,6 +774,20 @@ export class IgxCalendarComponent extends IgxMonthPickerBaseDirective implements
768774
}
769775
}
770776

777+
/**
778+
* @hidden
779+
* @internal
780+
*/
781+
public resetActiveDate(param?) {
782+
if (!this.monthViews) { return; }
783+
let dates = [];
784+
this.monthViews.map(mv => mv.dates).forEach(days => { dates = dates.concat(days.toArray()); });
785+
const date = dates.find(day => day.selected) || dates.find(day => day.isToday) || dates.find(d => d.isFocusable);
786+
if (date) {
787+
this.activeDate = date.date.date.toLocaleDateString();
788+
}
789+
}
790+
771791
/**
772792
* Keyboard navigation of the calendar
773793
* @hidden

projects/igniteui-angular/src/lib/calendar/days-view/days-view.component.html

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
[specialDates]="specialDates"
2828
[outOfRangeDates]="outOfRangeDates"
2929
[hideOutsideDays]="hideOutsideDays"
30+
[attr.tabindex]="tabIndex(day)"
3031
(onDateSelection)="selectDay($event)">
3132
{{ formattedDate(day.date) }}
3233
</igx-day-item>

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

+27-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ export class IgxDaysViewComponent extends IgxCalendarBaseDirective implements Do
6565
@Input()
6666
public showWeekNumbers: boolean;
6767

68+
/**
69+
* @hidden
70+
* @internal
71+
*/
72+
@Input()
73+
public set activeDate(value: string) {
74+
this._activeDate = value;
75+
this.activeDateChange.emit(this._activeDate);
76+
}
77+
78+
public get activeDate() {
79+
return this._activeDate;
80+
}
81+
6882
/**
6983
* @hidden
7084
*/
@@ -77,6 +91,12 @@ export class IgxDaysViewComponent extends IgxCalendarBaseDirective implements Do
7791
@Output()
7892
public onViewChanging = new EventEmitter<IViewChangingEventArgs>();
7993

94+
/**
95+
* @hidden
96+
*/
97+
@Output()
98+
public activeDateChange = new EventEmitter<string>();
99+
80100
/**
81101
* @hidden
82102
*/
@@ -97,6 +117,7 @@ export class IgxDaysViewComponent extends IgxCalendarBaseDirective implements Do
97117
* @hidden
98118
*/
99119
public prevMonthView: IgxDaysViewComponent;
120+
public _activeDate;
100121

101122
/**
102123
* The default css class applied to the component.
@@ -136,6 +157,10 @@ export class IgxDaysViewComponent extends IgxCalendarBaseDirective implements Do
136157
}
137158
}
138159

160+
public tabIndex(day: ICalendarDate): number {
161+
return this.activeDate && this.activeDate === day.date.toLocaleDateString() && day.isCurrentMonth ? 0 : -1;
162+
}
163+
139164
/**
140165
* Returns the week number by date
141166
*
@@ -361,7 +386,8 @@ export class IgxDaysViewComponent extends IgxCalendarBaseDirective implements Do
361386
public onKeydownArrow(event: KeyboardEvent) {
362387
event.preventDefault();
363388
event.stopPropagation();
364-
this.daysNavService.focusNextDate(event.target as HTMLElement, event.key);
389+
const day = this.daysNavService.focusNextDate(event.target as HTMLElement, event.key);
390+
this.activeDate = day?.date.date.toLocaleDateString();
365391
}
366392

367393
/**

projects/igniteui-angular/src/lib/calendar/days-view/daysview-navigation.service.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class IgxDaysViewNavigationService {
4444
}
4545
if (day && day.isFocusable) {
4646
day.nativeElement.focus();
47-
return;
47+
return day;
4848
}
4949
}
5050
break;
@@ -60,7 +60,7 @@ export class IgxDaysViewNavigationService {
6060
}
6161
if (day && day.isFocusable) {
6262
day.nativeElement.focus();
63-
return;
63+
return day;
6464
}
6565
}
6666
break;
@@ -76,7 +76,7 @@ export class IgxDaysViewNavigationService {
7676
}
7777
if (day && day.isFocusable) {
7878
day.nativeElement.focus();
79-
return;
79+
return day;
8080
}
8181
}
8282
break;
@@ -92,7 +92,7 @@ export class IgxDaysViewNavigationService {
9292
}
9393
if (day && day.isFocusable) {
9494
day.nativeElement.focus();
95-
return;
95+
return day;
9696
}
9797
}
9898
break;

src/app/calendar/calendar.sample.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ <h4 class="sample-title">Default Calendar</h4>
2323
<button igxButton="raised" igxRipple (click)="setSelection('range')">Range</button>
2424
</div>
2525
<igx-card>
26-
<igx-calendar #calendar [showWeekNumbers]="true" weekStart="1" selection="single" (viewDateChanged)="viewDateChanged($event)" (activeViewChanged)="activeViewChanged($event)" (onSelection)="onSelection($event)" [hideOutsideDays]="false" [monthsViewNumber]="3"></igx-calendar>
26+
<igx-calendar #calendar [showWeekNumbers]="true" weekStart="1" selection="multi" (viewDateChanged)="viewDateChanged($event)" (activeViewChanged)="activeViewChanged($event)" (onSelection)="onSelection($event)" [hideOutsideDays]="false" [monthsViewNumber]="3"></igx-calendar>
2727
</igx-card>
2828
</div>
2929

3030
<div class="calendar-sample">
3131
<h4 class="sample-title">Vertical Calendar</h4>
3232
<igx-card>
33-
<igx-calendar [showWeekNumbers]="true" weekStart="1" [vertical]="true"></igx-calendar>
33+
<igx-calendar [viewDate]="ppNovember" [showWeekNumbers]="true" weekStart="1" [vertical]="true"></igx-calendar>
3434
</igx-card>
3535
</div>
3636

src/app/calendar/calendar.sample.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,38 @@
1-
import { Component, OnInit, ViewChild } from '@angular/core';
1+
import { AfterViewInit, Component, OnInit, ViewChild } from '@angular/core';
22
import { IgxCalendarComponent, IgxDialogComponent, DateRangeType, CalendarView } from 'igniteui-angular';
3+
import { type } from 'os';
34
import { IViewDateChangeEventArgs } from '../../../projects/igniteui-angular/src/lib/calendar/calendar-base';
45

56
@Component({
67
selector: 'app-calendar-sample',
78
templateUrl: 'calendar.sample.html',
89
styleUrls: ['calendar.sample.scss']
910
})
10-
export class CalendarSampleComponent implements OnInit {
11+
export class CalendarSampleComponent implements OnInit, AfterViewInit {
1112
@ViewChild('calendar', { static: true }) calendar: IgxCalendarComponent;
1213
@ViewChild('calendar1', { static: true }) public calendar1: IgxCalendarComponent;
1314
@ViewChild('alert', { static: true }) public dialog: IgxDialogComponent;
1415
public range = [];
1516
public today = new Date();
17+
public ppNovember = new Date(this.today.getFullYear(), this.today.getMonth() + 1, 10);
1618
public rangeDisabled = [
1719
new Date(this.today.getFullYear(), this.today.getMonth(), 10),
1820
new Date(this.today.getFullYear(), this.today.getMonth(), 13)
1921
];
2022

2123
public ngOnInit() {
2224
this.calendar1.disabledDates = [{ type: DateRangeType.Between, dateRange: this.rangeDisabled }];
25+
this.calendar.selectDate([ new Date(this.today.getFullYear(), this.today.getMonth(), 10),
26+
new Date(this.today.getFullYear(), this.today.getMonth(), 17),
27+
new Date(this.today.getFullYear(), this.today.getMonth(), 27)]);
28+
}
29+
30+
public ngAfterViewInit() {
31+
//this.calendar.selectDate(new Date(this.today.getFullYear(), this.today.getMonth(), 10));
32+
/* [ new Date(this.today.getFullYear(), this.today.getMonth(), 10),
33+
new Date(this.today.getFullYear(), this.today.getMonth(), 17),
34+
new Date(this.today.getFullYear(), this.today.getMonth(), 27)]) */
35+
console.log(this.calendar.selectedDates);
2336
}
2437

2538
public selectPTOdays(dates: Date[]) {

0 commit comments

Comments
 (0)