@@ -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 ;
@@ -770,20 +788,6 @@ describe('MdMenu', () => {
770788 . toBe ( true , 'Expected focus to be back inside the root menu' ) ;
771789 } ) ;
772790
773- it ( 'should not shift focus to the sub-menu when it was opened by hover' , ( ) => {
774- compileTestComponent ( ) ;
775- instance . rootTriggerEl . nativeElement . click ( ) ;
776- fixture . detectChanges ( ) ;
777-
778- const levelOneTrigger = overlay . querySelector ( '#level-one-trigger' ) ! as HTMLElement ;
779-
780- dispatchMouseEvent ( levelOneTrigger , 'mouseenter' ) ;
781- fixture . detectChanges ( ) ;
782-
783- expect ( overlay . querySelectorAll ( '.mat-menu-panel' ) [ 1 ] . contains ( document . activeElement ) )
784- . toBe ( false , 'Expected focus to not be inside the nested menu' ) ;
785- } ) ;
786-
787791 it ( 'should position the sub-menu to the right edge of the trigger in ltr' , ( ) => {
788792 compileTestComponent ( ) ;
789793 instance . rootTriggerEl . nativeElement . style . position = 'fixed' ;
@@ -1057,6 +1061,7 @@ class CustomMenuPanel implements MdMenuPanel {
10571061 @ViewChild ( TemplateRef ) templateRef : TemplateRef < any > ;
10581062 @Output ( ) close = new EventEmitter < void | 'click' | 'keydown' > ( ) ;
10591063 focusFirstItem = ( ) => { } ;
1064+ resetActiveItem = ( ) => { } ;
10601065 setPositionClasses = ( ) => { } ;
10611066}
10621067
0 commit comments