File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -94,8 +94,8 @@ export class MatMenuItem extends _MatMenuItemMixinBase
94
94
}
95
95
96
96
/** Focuses the menu item. */
97
- focus ( origin : FocusOrigin = 'program' , options ?: FocusOptions ) : void {
98
- if ( this . _focusMonitor ) {
97
+ focus ( origin ? : FocusOrigin , options ?: FocusOptions ) : void {
98
+ if ( this . _focusMonitor && origin ) {
99
99
this . _focusMonitor . focusVia ( this . _getHostElement ( ) , origin , options ) ;
100
100
} else {
101
101
this . _getHostElement ( ) . focus ( options ) ;
Original file line number Diff line number Diff line change @@ -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 ( ) ;
You can’t perform that action at this time.
0 commit comments