Skip to content

Commit

Permalink
fix(datepicker): calendar keyboard controls not working if the user c…
Browse files Browse the repository at this point in the history
…licks on blank area (#9494)

Fixes the user not being able to use the keyboard controls on a calendar, if they click on one of the blank areas next to a cell. The issue comes from the calendar body not being focusable which ends up returning focus back to the body.
  • Loading branch information
crisbeto authored and jelbourn committed Jan 23, 2018
1 parent 6824375 commit 0b8955b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/datepicker/calendar.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</div>

<div class="mat-calendar-content" (keydown)="_handleCalendarBodyKeydown($event)"
[ngSwitch]="_currentView" cdkMonitorSubtreeFocus>
[ngSwitch]="_currentView" cdkMonitorSubtreeFocus tabindex="-1">
<mat-month-view
*ngSwitchCase="'month'"
[activeDate]="_activeDate"
Expand Down
4 changes: 4 additions & 0 deletions src/lib/datepicker/calendar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ describe('MatCalendar', () => {
expect(calendarInstance._activeDate).toEqual(new Date(2017, JAN, 31));
});

it('should make the calendar body focusable', () => {
expect(calendarBodyEl.getAttribute('tabindex')).toBe('-1');
});

describe('month view', () => {
it('should decrement date on left arrow press', () => {
dispatchKeyboardEvent(calendarBodyEl, 'keydown', LEFT_ARROW);
Expand Down

0 comments on commit 0b8955b

Please sign in to comment.