@@ -932,6 +932,60 @@ describe('MatMenu', () => {
932
932
. toBe ( 1 , 'Expected one open menu' ) ;
933
933
} ) ) ;
934
934
935
+ it ( 'should close submenu when hovering over disabled sibling item' , fakeAsync ( ( ) => {
936
+ compileTestComponent ( ) ;
937
+ instance . rootTriggerEl . nativeElement . click ( ) ;
938
+ fixture . detectChanges ( ) ;
939
+ tick ( 500 ) ;
940
+
941
+ const items = fixture . debugElement . queryAll ( By . directive ( MatMenuItem ) ) ;
942
+
943
+ dispatchFakeEvent ( items [ 0 ] . nativeElement , 'mouseenter' ) ;
944
+ fixture . detectChanges ( ) ;
945
+ tick ( 500 ) ;
946
+
947
+ expect ( overlay . querySelectorAll ( '.mat-menu-panel' ) . length )
948
+ . toBe ( 2 , 'Expected two open menus' ) ;
949
+
950
+ items [ 1 ] . componentInstance . disabled = true ;
951
+ fixture . detectChanges ( ) ;
952
+
953
+ // Note that we use `dispatchFakeEvent`, rather that `dispatchMouseEvent`, because the
954
+ // fake mouse events aren't being dispatched for disabled elements, whereas the
955
+ // native ones are.
956
+ dispatchFakeEvent ( items [ 1 ] . nativeElement , 'mouseenter' ) ;
957
+ fixture . detectChanges ( ) ;
958
+ tick ( 500 ) ;
959
+
960
+ expect ( overlay . querySelectorAll ( '.mat-menu-panel' ) . length )
961
+ . toBe ( 1 , 'Expected one open menu' ) ;
962
+ } ) ) ;
963
+
964
+ it ( 'should not open submenu when hovering over disabled trigger' , fakeAsync ( ( ) => {
965
+ compileTestComponent ( ) ;
966
+ instance . rootTriggerEl . nativeElement . click ( ) ;
967
+ fixture . detectChanges ( ) ;
968
+ tick ( 500 ) ;
969
+
970
+ expect ( overlay . querySelectorAll ( '.mat-menu-panel' ) . length )
971
+ . toBe ( 1 , 'Expected one open menu' ) ;
972
+
973
+ const item = fixture . debugElement . query ( By . directive ( MatMenuItem ) ) ;
974
+
975
+ // Note that we use `dispatchFakeEvent`, rather that `dispatchMouseEvent`, because the
976
+ // fake mouse events aren't being dispatched for disabled elements, whereas the
977
+ // native ones are.
978
+ item . componentInstance . disabled = true ;
979
+ fixture . detectChanges ( ) ;
980
+ dispatchFakeEvent ( item . nativeElement , 'mouseenter' ) ;
981
+ fixture . detectChanges ( ) ;
982
+ tick ( 500 ) ;
983
+
984
+ expect ( overlay . querySelectorAll ( '.mat-menu-panel' ) . length )
985
+ . toBe ( 1 , 'Expected to remain at one open menu' ) ;
986
+ } ) ) ;
987
+
988
+
935
989
it ( 'should open a nested menu when its trigger is clicked' , ( ) => {
936
990
compileTestComponent ( ) ;
937
991
instance . rootTriggerEl . nativeElement . click ( ) ;
0 commit comments