Skip to content

Commit 9ef8e59

Browse files
committed
fix(material/datepicker): fix Voiceover losing focus on PageDown
Fixes an issue where Voiceover loses focus when pressing PageDown/PageUp in the calendar to go to the next month/year (issue #24330). Adding a 20ms timeout seems to fix this. Note that this will not fully fix the issue until #24397 is merged. Address #24330.
1 parent 1c17a2c commit 9ef8e59

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/material/datepicker/calendar-body.ts

+16-10
Original file line numberDiff line numberDiff line change
@@ -195,21 +195,27 @@ export class MatCalendarBody implements OnChanges, OnDestroy {
195195
return cellNumber == this.activeCell;
196196
}
197197

198-
/** Focuses the active cell after the microtask queue is empty. */
198+
/**
199+
* Focuses the active cell after the microtask queue is empty.
200+
*
201+
* Adds a 20ms timeout to fix Voiceover losing focus when pressing PageUp/PageDown (issue #24330).
202+
*/
199203
_focusActiveCell(movePreview = true) {
200204
this._ngZone.runOutsideAngular(() => {
201205
this._ngZone.onStable.pipe(take(1)).subscribe(() => {
202-
const activeCell: HTMLElement | null = this._elementRef.nativeElement.querySelector(
203-
'.mat-calendar-body-active',
204-
);
206+
setTimeout(() => {
207+
const activeCell: HTMLElement | null = this._elementRef.nativeElement.querySelector(
208+
'.mat-calendar-body-active',
209+
);
205210

206-
if (activeCell) {
207-
if (!movePreview) {
208-
this._skipNextFocus = true;
209-
}
211+
if (activeCell) {
212+
if (!movePreview) {
213+
this._skipNextFocus = true;
214+
}
210215

211-
activeCell.focus();
212-
}
216+
activeCell.focus();
217+
}
218+
}, 20);
213219
});
214220
});
215221
}

src/material/datepicker/calendar-header.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<button mat-button type="button" class="mat-calendar-period-button"
44
(click)="currentPeriodClicked()" [attr.aria-label]="periodButtonLabel"
55
[attr.aria-describedby]="_buttonDescriptionId"
6-
[attr.aria-live]="'polite'">
6+
attr.aria-live="polite">
77
<span [attr.id]="_buttonDescriptionId">{{periodButtonText}}</span>
88
<svg class="mat-calendar-arrow" [class.mat-calendar-invert]="calendar.currentView !== 'month'"
99
viewBox="0 0 10 5" focusable="false">

0 commit comments

Comments
 (0)