File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -413,6 +413,13 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
413
413
_handleMousedown ( event : MouseEvent ) : void {
414
414
if ( ! isFakeMousedownFromScreenReader ( event ) ) {
415
415
this . _openedByMouse = true ;
416
+
417
+ // Since clicking on the trigger won't close the menu if it opens a sub-menu,
418
+ // we should prevent focus from moving onto it via click to avoid the
419
+ // highlight from lingering on the menu item.
420
+ if ( this . triggersSubmenu ) {
421
+ event . preventDefault ( ) ;
422
+ }
416
423
}
417
424
}
418
425
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ import {
29
29
dispatchMouseEvent ,
30
30
dispatchEvent ,
31
31
createKeyboardEvent ,
32
+ dispatchFakeEvent ,
32
33
} from '@angular/cdk/testing' ;
33
34
34
35
@@ -996,6 +997,15 @@ describe('MdMenu', () => {
996
997
expect ( overlay . querySelectorAll ( '.mat-menu-panel' ) . length ) . toBe ( 0 , 'Expected no open menus' ) ;
997
998
} ) ) ;
998
999
1000
+ it ( 'should prevent the default mousedown action if the menu item opens a sub-menu' , ( ) => {
1001
+ compileTestComponent ( ) ;
1002
+ instance . rootTrigger . openMenu ( ) ;
1003
+ fixture . detectChanges ( ) ;
1004
+
1005
+ const event = dispatchFakeEvent ( overlay . querySelector ( '[md-menu-item]' ) ! , 'mousedown' ) ;
1006
+
1007
+ expect ( event . defaultPrevented ) . toBe ( true ) ;
1008
+ } ) ;
999
1009
1000
1010
} ) ;
1001
1011
You can’t perform that action at this time.
0 commit comments