@@ -261,6 +261,26 @@ describe('MatMenu', () => {
261
261
tick ( 500 ) ;
262
262
} ) ) ;
263
263
264
+ it ( 'should move focus to another item if the active item is destroyed' , fakeAsync ( ( ) => {
265
+ const fixture = createComponent ( MenuWithRepeatedItems , [ ] , [ FakeIcon ] ) ;
266
+ fixture . detectChanges ( ) ;
267
+ const triggerEl = fixture . componentInstance . triggerEl . nativeElement ;
268
+
269
+ triggerEl . click ( ) ;
270
+ fixture . detectChanges ( ) ;
271
+ tick ( 500 ) ;
272
+
273
+ const items = overlayContainerElement . querySelectorAll ( '.mat-menu-panel .mat-menu-item' ) ;
274
+
275
+ expect ( document . activeElement ) . toBe ( items [ 0 ] ) ;
276
+
277
+ fixture . componentInstance . items . shift ( ) ;
278
+ fixture . detectChanges ( ) ;
279
+ tick ( 500 ) ;
280
+
281
+ expect ( document . activeElement ) . toBe ( items [ 1 ] ) ;
282
+ } ) ) ;
283
+
264
284
it ( 'should be able to set a custom class on the backdrop' , fakeAsync ( ( ) => {
265
285
const fixture = createComponent ( SimpleMenu , [ ] , [ FakeIcon ] ) ;
266
286
@@ -353,6 +373,7 @@ describe('MatMenu', () => {
353
373
// Add 50 items to make the menu scrollable
354
374
fixture . componentInstance . extraItems = new Array ( 50 ) . fill ( 'Hello there' ) ;
355
375
fixture . detectChanges ( ) ;
376
+ tick ( 50 ) ;
356
377
357
378
const triggerEl = fixture . componentInstance . triggerEl . nativeElement ;
358
379
dispatchFakeEvent ( triggerEl , 'mousedown' ) ;
@@ -3075,3 +3096,18 @@ class StaticAriaLabelledByMenu {}
3075
3096
template : '<mat-menu aria-describedby="some-element"></mat-menu>' ,
3076
3097
} )
3077
3098
class StaticAriaDescribedbyMenu { }
3099
+
3100
+ @Component ( {
3101
+ template : `
3102
+ <button [matMenuTriggerFor]="menu" #triggerEl>Toggle menu</button>
3103
+ <mat-menu #menu="matMenu">
3104
+ <button *ngFor="let item of items" mat-menu-item>{{item}}</button>
3105
+ </mat-menu>
3106
+ ` ,
3107
+ } )
3108
+ class MenuWithRepeatedItems {
3109
+ @ViewChild ( MatMenuTrigger , { static : false } ) trigger : MatMenuTrigger ;
3110
+ @ViewChild ( 'triggerEl' , { static : false } ) triggerEl : ElementRef < HTMLElement > ;
3111
+ @ViewChild ( MatMenu , { static : false } ) menu : MatMenu ;
3112
+ items = [ 'One' , 'Two' , 'Three' ] ;
3113
+ }
0 commit comments