Skip to content

refactor(datepicker): move keyboard events handlers into the views #9775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/lib/datepicker/calendar-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
import {
ChangeDetectionStrategy,
Component,
ElementRef,
EventEmitter,
Input,
Output,
ViewEncapsulation
ViewEncapsulation,
NgZone,
} from '@angular/core';

import {take} from 'rxjs/operators/take';

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

constructor(private _elementRef: ElementRef, private _ngZone: NgZone) { }

_cellClicked(cell: MatCalendarCell): void {
if (!this.allowDisabledSelection && !cell.enabled) {
return;
Expand All @@ -104,4 +108,13 @@ export class MatCalendarBody {

return cellNumber == this.activeCell;
}

/** Focuses the active cell after the microtask queue is empty. */
_focusActiveCell() {
this._ngZone.runOutsideAngular(() => {
this._ngZone.onStable.asObservable().pipe(take(1)).subscribe(() => {
this._elementRef.nativeElement.querySelector('.mat-calendar-body-active').focus();
});
});
}
}
5 changes: 2 additions & 3 deletions src/lib/datepicker/calendar.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
</div>
</div>

<div class="mat-calendar-content" (keydown)="_handleCalendarBodyKeydown($event)"
[ngSwitch]="_currentView" cdkMonitorSubtreeFocus tabindex="-1">
<div class="mat-calendar-content" [ngSwitch]="_currentView" cdkMonitorSubtreeFocus tabindex="-1">
<mat-month-view
*ngSwitchCase="'month'"
[activeDate]="_activeDate"
[(activeDate)]="_activeDate"
[selected]="selected"
[dateFilter]="dateFilter"
[maxDate]="maxDate"
Expand Down
Loading