@@ -200,6 +200,26 @@ describe('MatMenu', () => {
200
200
expect ( document . activeElement ) . toBe ( triggerEl ) ;
201
201
} ) ;
202
202
203
+ it ( 'should move focus to another item if the active item is destroyed' , fakeAsync ( ( ) => {
204
+ const fixture = createComponent ( MenuWithRepeatedItems , [ ] , [ FakeIcon ] ) ;
205
+ fixture . detectChanges ( ) ;
206
+ const triggerEl = fixture . componentInstance . triggerEl . nativeElement ;
207
+
208
+ triggerEl . click ( ) ;
209
+ fixture . detectChanges ( ) ;
210
+ tick ( 500 ) ;
211
+
212
+ const items = overlayContainerElement . querySelectorAll ( '.mat-menu-panel .mat-menu-item' ) ;
213
+
214
+ expect ( document . activeElement ) . toBe ( items [ 0 ] ) ;
215
+
216
+ fixture . componentInstance . items . shift ( ) ;
217
+ fixture . detectChanges ( ) ;
218
+ tick ( 500 ) ;
219
+
220
+ expect ( document . activeElement ) . toBe ( items [ 1 ] ) ;
221
+ } ) ) ;
222
+
203
223
it ( 'should be able to set a custom class on the backdrop' , fakeAsync ( ( ) => {
204
224
const fixture = createComponent ( SimpleMenu , [ ] , [ FakeIcon ] ) ;
205
225
@@ -257,6 +277,7 @@ describe('MatMenu', () => {
257
277
// Add 50 items to make the menu scrollable
258
278
fixture . componentInstance . extraItems = new Array ( 50 ) . fill ( 'Hello there' ) ;
259
279
fixture . detectChanges ( ) ;
280
+ tick ( 50 ) ;
260
281
261
282
const triggerEl = fixture . componentInstance . triggerEl . nativeElement ;
262
283
dispatchFakeEvent ( triggerEl , 'mousedown' ) ;
@@ -2392,7 +2413,6 @@ class DynamicPanelMenu {
2392
2413
@ViewChild ( 'two' , { static : false } ) secondMenu : MatMenu ;
2393
2414
}
2394
2415
2395
-
2396
2416
@Component ( {
2397
2417
template : `
2398
2418
<button [matMenuTriggerFor]="menu">Toggle menu</button>
@@ -2447,3 +2467,18 @@ class LazyMenuWithOnPush {
2447
2467
@ViewChild ( 'triggerEl' , { static : false , read : ElementRef } ) rootTrigger : ElementRef ;
2448
2468
@ViewChild ( 'menuItem' , { static : false , read : ElementRef } ) menuItemWithSubmenu : ElementRef ;
2449
2469
}
2470
+
2471
+ @Component ( {
2472
+ template : `
2473
+ <button [matMenuTriggerFor]="menu" #triggerEl>Toggle menu</button>
2474
+ <mat-menu #menu="matMenu">
2475
+ <button *ngFor="let item of items" mat-menu-item>{{item}}</button>
2476
+ </mat-menu>
2477
+ `
2478
+ } )
2479
+ class MenuWithRepeatedItems {
2480
+ @ViewChild ( MatMenuTrigger , { static : false } ) trigger : MatMenuTrigger ;
2481
+ @ViewChild ( 'triggerEl' , { static : false } ) triggerEl : ElementRef < HTMLElement > ;
2482
+ @ViewChild ( MatMenu , { static : false } ) menu : MatMenu ;
2483
+ items = [ 'One' , 'Two' , 'Three' ] ;
2484
+ }
0 commit comments