@@ -259,6 +259,26 @@ describe('MatMenu', () => {
259
259
tick ( 500 ) ;
260
260
} ) ) ;
261
261
262
+ it ( 'should move focus to another item if the active item is destroyed' , fakeAsync ( ( ) => {
263
+ const fixture = createComponent ( MenuWithRepeatedItems , [ ] , [ FakeIcon ] ) ;
264
+ fixture . detectChanges ( ) ;
265
+ const triggerEl = fixture . componentInstance . triggerEl . nativeElement ;
266
+
267
+ triggerEl . click ( ) ;
268
+ fixture . detectChanges ( ) ;
269
+ tick ( 500 ) ;
270
+
271
+ const items = overlayContainerElement . querySelectorAll ( '.mat-menu-panel .mat-menu-item' ) ;
272
+
273
+ expect ( document . activeElement ) . toBe ( items [ 0 ] ) ;
274
+
275
+ fixture . componentInstance . items . shift ( ) ;
276
+ fixture . detectChanges ( ) ;
277
+ tick ( 500 ) ;
278
+
279
+ expect ( document . activeElement ) . toBe ( items [ 1 ] ) ;
280
+ } ) ) ;
281
+
262
282
it ( 'should be able to set a custom class on the backdrop' , fakeAsync ( ( ) => {
263
283
const fixture = createComponent ( SimpleMenu , [ ] , [ FakeIcon ] ) ;
264
284
@@ -351,6 +371,7 @@ describe('MatMenu', () => {
351
371
// Add 50 items to make the menu scrollable
352
372
fixture . componentInstance . extraItems = new Array ( 50 ) . fill ( 'Hello there' ) ;
353
373
fixture . detectChanges ( ) ;
374
+ tick ( 50 ) ;
354
375
355
376
const triggerEl = fixture . componentInstance . triggerEl . nativeElement ;
356
377
dispatchFakeEvent ( triggerEl , 'mousedown' ) ;
@@ -3053,3 +3074,18 @@ class StaticAriaLabelledByMenu {}
3053
3074
template : '<mat-menu aria-describedby="some-element"></mat-menu>' ,
3054
3075
} )
3055
3076
class StaticAriaDescribedbyMenu { }
3077
+
3078
+ @Component ( {
3079
+ template : `
3080
+ <button [matMenuTriggerFor]="menu" #triggerEl>Toggle menu</button>
3081
+ <mat-menu #menu="matMenu">
3082
+ <button *ngFor="let item of items" mat-menu-item>{{item}}</button>
3083
+ </mat-menu>
3084
+ ` ,
3085
+ } )
3086
+ class MenuWithRepeatedItems {
3087
+ @ViewChild ( MatMenuTrigger , { static : false } ) trigger : MatMenuTrigger ;
3088
+ @ViewChild ( 'triggerEl' , { static : false } ) triggerEl : ElementRef < HTMLElement > ;
3089
+ @ViewChild ( MatMenu , { static : false } ) menu : MatMenu ;
3090
+ items = [ 'One' , 'Two' , 'Three' ] ;
3091
+ }
0 commit comments