@@ -33,6 +33,7 @@ import {
3333 dispatchEvent ,
3434 createKeyboardEvent ,
3535 createMouseEvent ,
36+ dispatchFakeEvent ,
3637} from '@angular/cdk/testing' ;
3738
3839
@@ -191,6 +192,23 @@ describe('MatMenu', () => {
191192 expect ( fixture . componentInstance . items . last . getLabel ( ) ) . toBe ( 'Item with an icon' ) ;
192193 } ) ;
193194
195+ it ( 'should focus the menu panel root node when it was opened by mouse' , ( ) => {
196+ const fixture = TestBed . createComponent ( SimpleMenu ) ;
197+
198+ fixture . detectChanges ( ) ;
199+
200+ const triggerEl = fixture . componentInstance . triggerEl . nativeElement ;
201+
202+ dispatchFakeEvent ( triggerEl , 'mousedown' ) ;
203+ triggerEl . click ( ) ;
204+ fixture . detectChanges ( ) ;
205+
206+ const panel = overlayContainerElement . querySelector ( '.mat-menu-panel' ) ;
207+
208+ expect ( panel ) . toBeTruthy ( 'Expected the panel to be rendered.' ) ;
209+ expect ( document . activeElement ) . toBe ( panel , 'Expected the panel to be focused.' ) ;
210+ } ) ;
211+
194212 describe ( 'positions' , ( ) => {
195213 let fixture : ComponentFixture < PositionedMenu > ;
196214 let panel : HTMLElement ;
@@ -811,20 +829,6 @@ describe('MatMenu', () => {
811829 . toBe ( true , 'Expected focus to be back inside the root menu' ) ;
812830 } ) ;
813831
814- it ( 'should not shift focus to the sub-menu when it was opened by hover' , ( ) => {
815- compileTestComponent ( ) ;
816- instance . rootTriggerEl . nativeElement . click ( ) ;
817- fixture . detectChanges ( ) ;
818-
819- const levelOneTrigger = overlay . querySelector ( '#level-one-trigger' ) ! as HTMLElement ;
820-
821- dispatchMouseEvent ( levelOneTrigger , 'mouseenter' ) ;
822- fixture . detectChanges ( ) ;
823-
824- expect ( overlay . querySelectorAll ( '.mat-menu-panel' ) [ 1 ] . contains ( document . activeElement ) )
825- . toBe ( false , 'Expected focus to not be inside the nested menu' ) ;
826- } ) ;
827-
828832 it ( 'should position the sub-menu to the right edge of the trigger in ltr' , ( ) => {
829833 compileTestComponent ( ) ;
830834 instance . rootTriggerEl . nativeElement . style . position = 'fixed' ;
@@ -1179,6 +1183,7 @@ class CustomMenuPanel implements MatMenuPanel {
11791183 @ViewChild ( TemplateRef ) templateRef : TemplateRef < any > ;
11801184 @Output ( ) close = new EventEmitter < void | 'click' | 'keydown' > ( ) ;
11811185 focusFirstItem = ( ) => { } ;
1186+ resetActiveItem = ( ) => { } ;
11821187 setPositionClasses = ( ) => { } ;
11831188}
11841189
0 commit comments