@@ -30,6 +30,7 @@ import {
3030 dispatchEvent ,
3131 createKeyboardEvent ,
3232 createMouseEvent ,
33+ dispatchFakeEvent ,
3334} from '@angular/cdk/testing' ;
3435
3536
@@ -174,6 +175,23 @@ describe('MdMenu', () => {
174175 expect ( fixture . destroy . bind ( fixture ) ) . not . toThrow ( ) ;
175176 } ) ;
176177
178+ it ( 'should focus the menu panel root node when it was opened by mouse' , ( ) => {
179+ const fixture = TestBed . createComponent ( SimpleMenu ) ;
180+
181+ fixture . detectChanges ( ) ;
182+
183+ const triggerEl = fixture . componentInstance . triggerEl . nativeElement ;
184+
185+ dispatchFakeEvent ( triggerEl , 'mousedown' ) ;
186+ triggerEl . click ( ) ;
187+ fixture . detectChanges ( ) ;
188+
189+ const panel = overlayContainerElement . querySelector ( '.mat-menu-panel' ) ;
190+
191+ expect ( panel ) . toBeTruthy ( 'Expected the panel to be rendered.' ) ;
192+ expect ( document . activeElement ) . toBe ( panel , 'Expected the panel to be focused.' ) ;
193+ } ) ;
194+
177195 describe ( 'positions' , ( ) => {
178196 let fixture : ComponentFixture < PositionedMenu > ;
179197 let panel : HTMLElement ;
@@ -780,20 +798,6 @@ describe('MdMenu', () => {
780798 . toBe ( true , 'Expected focus to be back inside the root menu' ) ;
781799 } ) ;
782800
783- it ( 'should not shift focus to the sub-menu when it was opened by hover' , ( ) => {
784- compileTestComponent ( ) ;
785- instance . rootTriggerEl . nativeElement . click ( ) ;
786- fixture . detectChanges ( ) ;
787-
788- const levelOneTrigger = overlay . querySelector ( '#level-one-trigger' ) ! as HTMLElement ;
789-
790- dispatchMouseEvent ( levelOneTrigger , 'mouseenter' ) ;
791- fixture . detectChanges ( ) ;
792-
793- expect ( overlay . querySelectorAll ( '.mat-menu-panel' ) [ 1 ] . contains ( document . activeElement ) )
794- . toBe ( false , 'Expected focus to not be inside the nested menu' ) ;
795- } ) ;
796-
797801 it ( 'should position the sub-menu to the right edge of the trigger in ltr' , ( ) => {
798802 compileTestComponent ( ) ;
799803 instance . rootTriggerEl . nativeElement . style . position = 'fixed' ;
@@ -1125,6 +1129,7 @@ class CustomMenuPanel implements MdMenuPanel {
11251129 @ViewChild ( TemplateRef ) templateRef : TemplateRef < any > ;
11261130 @Output ( ) close = new EventEmitter < void | 'click' | 'keydown' > ( ) ;
11271131 focusFirstItem = ( ) => { } ;
1132+ resetActiveItem = ( ) => { } ;
11281133 setPositionClasses = ( ) => { } ;
11291134}
11301135
0 commit comments