@@ -238,6 +238,26 @@ describe('MatMenu', () => {
238
238
tick ( 500 ) ;
239
239
} ) ) ;
240
240
241
+ it ( 'should move focus to another item if the active item is destroyed' , fakeAsync ( ( ) => {
242
+ const fixture = createComponent ( MenuWithRepeatedItems , [ ] , [ FakeIcon ] ) ;
243
+ fixture . detectChanges ( ) ;
244
+ const triggerEl = fixture . componentInstance . triggerEl . nativeElement ;
245
+
246
+ triggerEl . click ( ) ;
247
+ fixture . detectChanges ( ) ;
248
+ tick ( 500 ) ;
249
+
250
+ const items = overlayContainerElement . querySelectorAll ( '.mat-menu-panel .mat-menu-item' ) ;
251
+
252
+ expect ( document . activeElement ) . toBe ( items [ 0 ] ) ;
253
+
254
+ fixture . componentInstance . items . shift ( ) ;
255
+ fixture . detectChanges ( ) ;
256
+ tick ( 500 ) ;
257
+
258
+ expect ( document . activeElement ) . toBe ( items [ 1 ] ) ;
259
+ } ) ) ;
260
+
241
261
it ( 'should be able to set a custom class on the backdrop' , fakeAsync ( ( ) => {
242
262
const fixture = createComponent ( SimpleMenu , [ ] , [ FakeIcon ] ) ;
243
263
@@ -330,6 +350,7 @@ describe('MatMenu', () => {
330
350
// Add 50 items to make the menu scrollable
331
351
fixture . componentInstance . extraItems = new Array ( 50 ) . fill ( 'Hello there' ) ;
332
352
fixture . detectChanges ( ) ;
353
+ tick ( 50 ) ;
333
354
334
355
const triggerEl = fixture . componentInstance . triggerEl . nativeElement ;
335
356
dispatchFakeEvent ( triggerEl , 'mousedown' ) ;
@@ -3046,3 +3067,18 @@ class StaticAriaLabelledByMenu {}
3046
3067
template : '<mat-menu aria-describedby="some-element"></mat-menu>' ,
3047
3068
} )
3048
3069
class StaticAriaDescribedbyMenu { }
3070
+
3071
+ @Component ( {
3072
+ template : `
3073
+ <button [matMenuTriggerFor]="menu" #triggerEl>Toggle menu</button>
3074
+ <mat-menu #menu="matMenu">
3075
+ <button *ngFor="let item of items" mat-menu-item>{{item}}</button>
3076
+ </mat-menu>
3077
+ ` ,
3078
+ } )
3079
+ class MenuWithRepeatedItems {
3080
+ @ViewChild ( MatMenuTrigger , { static : false } ) trigger : MatMenuTrigger ;
3081
+ @ViewChild ( 'triggerEl' , { static : false } ) triggerEl : ElementRef < HTMLElement > ;
3082
+ @ViewChild ( MatMenu , { static : false } ) menu : MatMenu ;
3083
+ items = [ 'One' , 'Two' , 'Three' ] ;
3084
+ }
0 commit comments