@@ -615,6 +615,25 @@ describe('MatMenu', () => {
615
615
expect ( items . every ( item => item . getAttribute ( 'role' ) === 'menuitemcheckbox' ) ) . toBe ( true ) ;
616
616
} ) ;
617
617
618
+ it ( 'should not change focus origin if origin not specified for menu items' , ( ) => {
619
+ const fixture = createComponent ( MenuWithCheckboxItems ) ;
620
+ fixture . detectChanges ( ) ;
621
+ fixture . componentInstance . trigger . openMenu ( ) ;
622
+ fixture . detectChanges ( ) ;
623
+
624
+ let [ firstMenuItemDebugEl , secondMenuItemDebugEl ] =
625
+ fixture . debugElement . queryAll ( By . css ( '.mat-menu-item' ) ) ! ;
626
+
627
+ const firstMenuItemInstance = firstMenuItemDebugEl . componentInstance as MatMenuItem ;
628
+ const secondMenuItemInstance = secondMenuItemDebugEl . componentInstance as MatMenuItem ;
629
+
630
+ firstMenuItemInstance . focus ( 'mouse' ) ;
631
+ secondMenuItemInstance . focus ( ) ;
632
+
633
+ expect ( secondMenuItemDebugEl . nativeElement . classList ) . toContain ( 'cdk-focused' ) ;
634
+ expect ( secondMenuItemDebugEl . nativeElement . classList ) . toContain ( 'cdk-mouse-focused' ) ;
635
+ } ) ;
636
+
618
637
it ( 'should not throw an error on destroy' , ( ) => {
619
638
const fixture = createComponent ( SimpleMenu , [ ] , [ FakeIcon ] ) ;
620
639
expect ( fixture . destroy . bind ( fixture ) ) . not . toThrow ( ) ;
@@ -2006,6 +2025,24 @@ describe('MatMenu', () => {
2006
2025
. toContain ( 'mat-elevation-z4' , 'Expected menu to have the proper updated elevation.' ) ;
2007
2026
} ) ) ;
2008
2027
2028
+ it ( 'should not change focus origin if origin not specified for menu trigger' ,
2029
+ fakeAsync ( ( ) => {
2030
+ compileTestComponent ( ) ;
2031
+
2032
+ instance . levelOneTrigger . openMenu ( ) ;
2033
+ instance . levelOneTrigger . focus ( 'mouse' ) ;
2034
+ fixture . detectChanges ( ) ;
2035
+
2036
+ instance . levelTwoTrigger . focus ( ) ;
2037
+ fixture . detectChanges ( ) ;
2038
+ tick ( 500 ) ;
2039
+
2040
+ const levelTwoTrigger = overlay . querySelector ( '#level-two-trigger' ) ! as HTMLElement ;
2041
+
2042
+ expect ( levelTwoTrigger . classList ) . toContain ( 'cdk-focused' ) ;
2043
+ expect ( levelTwoTrigger . classList ) . toContain ( 'cdk-mouse-focused' ) ;
2044
+ } ) ) ;
2045
+
2009
2046
it ( 'should not increase the elevation if the user specified a custom one' , ( ) => {
2010
2047
const elevationFixture = createComponent ( NestedMenuCustomElevation ) ;
2011
2048
0 commit comments