Skip to content

Commit 0b8955b

Browse files
crisbetojelbourn
authored andcommitted
fix(datepicker): calendar keyboard controls not working if the user clicks 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.
1 parent 6824375 commit 0b8955b

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/lib/datepicker/calendar.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</div>
2222

2323
<div class="mat-calendar-content" (keydown)="_handleCalendarBodyKeydown($event)"
24-
[ngSwitch]="_currentView" cdkMonitorSubtreeFocus>
24+
[ngSwitch]="_currentView" cdkMonitorSubtreeFocus tabindex="-1">
2525
<mat-month-view
2626
*ngSwitchCase="'month'"
2727
[activeDate]="_activeDate"

src/lib/datepicker/calendar.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ describe('MatCalendar', () => {
220220
expect(calendarInstance._activeDate).toEqual(new Date(2017, JAN, 31));
221221
});
222222

223+
it('should make the calendar body focusable', () => {
224+
expect(calendarBodyEl.getAttribute('tabindex')).toBe('-1');
225+
});
226+
223227
describe('month view', () => {
224228
it('should decrement date on left arrow press', () => {
225229
dispatchKeyboardEvent(calendarBodyEl, 'keydown', LEFT_ARROW);

0 commit comments

Comments
 (0)