|
6 | 6 | * found in the LICENSE file at https://angular.dev/license
|
7 | 7 | */
|
8 | 8 |
|
9 |
| -import {FocusableOption, FocusMonitor, FocusOrigin} from '@angular/cdk/a11y'; |
| 9 | +import { |
| 10 | + FOCUS_MONITOR_DEFAULT_OPTIONS, |
| 11 | + FocusableOption, |
| 12 | + FocusMonitor, |
| 13 | + FocusMonitorDetectionMode, |
| 14 | + FocusOrigin, |
| 15 | +} from '@angular/cdk/a11y'; |
10 | 16 | import {ENTER, hasModifierKey, SPACE} from '@angular/cdk/keycodes';
|
11 | 17 | import {
|
12 | 18 | AfterViewInit,
|
@@ -57,6 +63,15 @@ import {_StructuralStylesLoader} from '../core';
|
57 | 63 | '(click)': '_toggle()',
|
58 | 64 | '(keydown)': '_keydown($event)',
|
59 | 65 | },
|
| 66 | + providers: [ |
| 67 | + FocusMonitor, |
| 68 | + { |
| 69 | + provide: FOCUS_MONITOR_DEFAULT_OPTIONS, |
| 70 | + useValue: { |
| 71 | + detectionMode: FocusMonitorDetectionMode.EVENTUAL, |
| 72 | + }, |
| 73 | + }, |
| 74 | + ], |
60 | 75 | })
|
61 | 76 | export class MatExpansionPanelHeader implements AfterViewInit, OnDestroy, FocusableOption {
|
62 | 77 | panel = inject(MatExpansionPanel, {host: true});
|
@@ -98,9 +113,7 @@ export class MatExpansionPanelHeader implements AfterViewInit, OnDestroy, Focusa
|
98 | 113 | ).subscribe(() => this._changeDetectorRef.markForCheck());
|
99 | 114 |
|
100 | 115 | // Avoids focus being lost if the panel contained the focused element and was closed.
|
101 |
| - panel.closed |
102 |
| - .pipe(filter(() => panel._containsFocus())) |
103 |
| - .subscribe(() => this._focusMonitor.focusVia(this._element, 'program')); |
| 116 | + panel.closed.pipe(filter(() => panel._containsFocus())).subscribe(() => this.focus()); |
104 | 117 |
|
105 | 118 | if (defaultOptions) {
|
106 | 119 | this.expandedHeight = defaultOptions.expandedHeight;
|
|
0 commit comments