@@ -29,6 +29,7 @@ import {
2929 dispatchMouseEvent ,
3030 dispatchEvent ,
3131 createKeyboardEvent ,
32+ dispatchFakeEvent ,
3233} from '@angular/cdk/testing' ;
3334
3435
@@ -173,6 +174,23 @@ describe('MdMenu', () => {
173174 expect ( fixture . destroy . bind ( fixture ) ) . not . toThrow ( ) ;
174175 } ) ;
175176
177+ it ( 'should focus the menu panel root node when it was opened by mouse' , ( ) => {
178+ const fixture = TestBed . createComponent ( SimpleMenu ) ;
179+
180+ fixture . detectChanges ( ) ;
181+
182+ const triggerEl = fixture . componentInstance . triggerEl . nativeElement ;
183+
184+ dispatchFakeEvent ( triggerEl , 'mousedown' ) ;
185+ triggerEl . click ( ) ;
186+ fixture . detectChanges ( ) ;
187+
188+ const panel = overlayContainerElement . querySelector ( '.mat-menu-panel' ) ;
189+
190+ expect ( panel ) . toBeTruthy ( 'Expected the panel to be rendered.' ) ;
191+ expect ( document . activeElement ) . toBe ( panel , 'Expected the panel to be focused.' ) ;
192+ } ) ;
193+
176194 describe ( 'positions' , ( ) => {
177195 let fixture : ComponentFixture < PositionedMenu > ;
178196 let panel : HTMLElement ;
@@ -779,20 +797,6 @@ describe('MdMenu', () => {
779797 . toBe ( true , 'Expected focus to be back inside the root menu' ) ;
780798 } ) ;
781799
782- it ( 'should not shift focus to the sub-menu when it was opened by hover' , ( ) => {
783- compileTestComponent ( ) ;
784- instance . rootTriggerEl . nativeElement . click ( ) ;
785- fixture . detectChanges ( ) ;
786-
787- const levelOneTrigger = overlay . querySelector ( '#level-one-trigger' ) ! as HTMLElement ;
788-
789- dispatchMouseEvent ( levelOneTrigger , 'mouseenter' ) ;
790- fixture . detectChanges ( ) ;
791-
792- expect ( overlay . querySelectorAll ( '.mat-menu-panel' ) [ 1 ] . contains ( document . activeElement ) )
793- . toBe ( false , 'Expected focus to not be inside the nested menu' ) ;
794- } ) ;
795-
796800 it ( 'should position the sub-menu to the right edge of the trigger in ltr' , ( ) => {
797801 compileTestComponent ( ) ;
798802 instance . rootTriggerEl . nativeElement . style . position = 'fixed' ;
@@ -1093,6 +1097,7 @@ class CustomMenuPanel implements MdMenuPanel {
10931097 @ViewChild ( TemplateRef ) templateRef : TemplateRef < any > ;
10941098 @Output ( ) close = new EventEmitter < void | 'click' | 'keydown' > ( ) ;
10951099 focusFirstItem = ( ) => { } ;
1100+ resetActiveItem = ( ) => { } ;
10961101 setPositionClasses = ( ) => { } ;
10971102}
10981103
0 commit comments