Skip to content

Commit 916d3ba

Browse files
julianobrasiltinayuangao
authored andcommitted
refactor(datepicker): move keyboard events handlers into the views (#9775)
1 parent 61aedc5 commit 916d3ba

15 files changed

+886
-696
lines changed

src/lib/datepicker/calendar-body.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
import {
1010
ChangeDetectionStrategy,
1111
Component,
12+
ElementRef,
1213
EventEmitter,
1314
Input,
1415
Output,
15-
ViewEncapsulation
16+
ViewEncapsulation,
17+
NgZone,
1618
} from '@angular/core';
17-
19+
import {take} from 'rxjs/operators/take';
1820

1921
/**
2022
* An internal class that represents the data corresponding to a single calendar cell.
@@ -81,6 +83,8 @@ export class MatCalendarBody {
8183
/** Emits when a new value is selected. */
8284
@Output() readonly selectedValueChange: EventEmitter<number> = new EventEmitter<number>();
8385

86+
constructor(private _elementRef: ElementRef, private _ngZone: NgZone) { }
87+
8488
_cellClicked(cell: MatCalendarCell): void {
8589
if (!this.allowDisabledSelection && !cell.enabled) {
8690
return;
@@ -104,4 +108,13 @@ export class MatCalendarBody {
104108

105109
return cellNumber == this.activeCell;
106110
}
111+
112+
/** Focuses the active cell after the microtask queue is empty. */
113+
_focusActiveCell() {
114+
this._ngZone.runOutsideAngular(() => {
115+
this._ngZone.onStable.asObservable().pipe(take(1)).subscribe(() => {
116+
this._elementRef.nativeElement.querySelector('.mat-calendar-body-active').focus();
117+
});
118+
});
119+
}
107120
}

src/lib/datepicker/calendar.html

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@
2020
</div>
2121
</div>
2222

23-
<div class="mat-calendar-content" (keydown)="_handleCalendarBodyKeydown($event)"
24-
[ngSwitch]="_currentView" cdkMonitorSubtreeFocus tabindex="-1">
23+
<div class="mat-calendar-content" [ngSwitch]="_currentView" cdkMonitorSubtreeFocus tabindex="-1">
2524
<mat-month-view
2625
*ngSwitchCase="'month'"
27-
[activeDate]="_activeDate"
26+
[(activeDate)]="_activeDate"
2827
[selected]="selected"
2928
[dateFilter]="dateFilter"
3029
[maxDate]="maxDate"

0 commit comments

Comments
 (0)