Skip to content

Commit 5939b36

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 620283b commit 5939b36

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/material/datepicker/calendar-body.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
OnDestroy,
2121
AfterViewChecked,
2222
} from '@angular/core';
23-
import {take} from 'rxjs/operators';
23+
import {delay, take} from 'rxjs/operators';
2424

2525
/** Extra CSS classes that can be associated with a calendar cell. */
2626
export type MatCalendarCellCssClasses = string | string[] | Set<string> | {[key: string]: any};
@@ -31,6 +31,8 @@ export type MatCalendarCellClassFunction<D> = (
3131
view: 'month' | 'year' | 'multi-year',
3232
) => MatCalendarCellCssClasses;
3333

34+
export const FOCUS_ACTIVE_CELL_DELAY = 20;
35+
3436
/**
3537
* An internal class that represents the data corresponding to a single calendar cell.
3638
* @docs-private
@@ -216,10 +218,14 @@ export class MatCalendarBody implements OnChanges, OnDestroy, AfterViewChecked {
216218
return cellNumber == this.activeCell;
217219
}
218220

219-
/** Focuses the active cell after the microtask queue is empty. */
221+
/**
222+
* Focuses the active cell after the microtask queue is empty.
223+
*
224+
* Adds a 20ms delay to fix Voiceover losing focus when pressing PageUp/PageDown (issue #24330).
225+
*/
220226
_focusActiveCell(movePreview = true) {
221227
this._ngZone.runOutsideAngular(() => {
222-
this._ngZone.onStable.pipe(take(1)).subscribe(() => {
228+
this._ngZone.onStable.pipe(take(1), delay(FOCUS_ACTIVE_CELL_DELAY)).subscribe(() => {
223229
const activeCell: HTMLElement | null = this._elementRef.nativeElement.querySelector(
224230
'.mat-calendar-body-active',
225231
);

0 commit comments

Comments
 (0)