Skip to content

Commit 3f294ef

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 33b6773 commit 3f294ef

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

src/material/datepicker/calendar-body.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -195,23 +195,29 @@ 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) {
200-
this._ngZone.runOutsideAngular(() => {
201-
this._ngZone.onStable.pipe(take(1)).subscribe(() => {
202-
const activeCell: HTMLElement | null = this._elementRef.nativeElement.querySelector(
203-
'.mat-calendar-body-active',
204-
);
205-
206-
if (activeCell) {
207-
if (!movePreview) {
208-
this._skipNextFocus = true;
204+
setTimeout(() => {
205+
this._ngZone.runOutsideAngular(() => {
206+
this._ngZone.onStable.pipe(take(1)).subscribe(() => {
207+
const activeCell: HTMLElement | null = this._elementRef.nativeElement.querySelector(
208+
'.mat-calendar-body-active',
209+
);
210+
211+
if (activeCell) {
212+
if (!movePreview) {
213+
this._skipNextFocus = true;
214+
}
215+
216+
activeCell.focus();
209217
}
210-
211-
activeCell.focus();
212-
}
218+
});
213219
});
214-
});
220+
}, 20);
215221
}
216222

217223
/** Gets whether a value is the start of the main range. */

0 commit comments

Comments
 (0)