@@ -14,6 +14,7 @@ import {
14
14
QueryList ,
15
15
Type ,
16
16
Provider ,
17
+ ChangeDetectionStrategy ,
17
18
} from '@angular/core' ;
18
19
import { Direction , Directionality } from '@angular/cdk/bidi' ;
19
20
import { OverlayContainer , Overlay } from '@angular/cdk/overlay' ;
@@ -243,6 +244,42 @@ describe('MDC-based MatMenu', () => {
243
244
expect ( backdrop . classList ) . toContain ( 'custom-backdrop' ) ;
244
245
} ) ) ;
245
246
247
+
248
+ it ( 'should be able to set a custom class on the overlay panel' , fakeAsync ( ( ) => {
249
+ const optionsProvider = {
250
+ provide : MAT_MENU_DEFAULT_OPTIONS ,
251
+ useValue : { overlayPanelClass : 'custom-panel-class' }
252
+ } ;
253
+ const fixture = createComponent ( SimpleMenu , [ optionsProvider ] , [ FakeIcon ] ) ;
254
+
255
+ fixture . detectChanges ( ) ;
256
+ fixture . componentInstance . trigger . openMenu ( ) ;
257
+ fixture . detectChanges ( ) ;
258
+ tick ( 500 ) ;
259
+
260
+ const overlayPane = < HTMLElement > overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) ;
261
+
262
+ expect ( overlayPane . classList ) . toContain ( 'custom-panel-class' ) ;
263
+ } ) ) ;
264
+
265
+ it ( 'should be able to set a custom classes on the overlay panel' , fakeAsync ( ( ) => {
266
+ const optionsProvider = {
267
+ provide : MAT_MENU_DEFAULT_OPTIONS ,
268
+ useValue : { overlayPanelClass : [ 'custom-panel-class-1' , 'custom-panel-class-2' ] }
269
+ } ;
270
+ const fixture = createComponent ( SimpleMenu , [ optionsProvider ] , [ FakeIcon ] ) ;
271
+
272
+ fixture . detectChanges ( ) ;
273
+ fixture . componentInstance . trigger . openMenu ( ) ;
274
+ fixture . detectChanges ( ) ;
275
+ tick ( 500 ) ;
276
+
277
+ const overlayPane = < HTMLElement > overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) ;
278
+
279
+ expect ( overlayPane . classList ) . toContain ( 'custom-panel-class-1' ) ;
280
+ expect ( overlayPane . classList ) . toContain ( 'custom-panel-class-2' ) ;
281
+ } ) ) ;
282
+
246
283
it ( 'should restore focus to the root trigger when the menu was opened by mouse' , fakeAsync ( ( ) => {
247
284
const fixture = createComponent ( SimpleMenu , [ ] , [ FakeIcon ] ) ;
248
285
fixture . detectChanges ( ) ;
@@ -906,6 +943,25 @@ describe('MDC-based MatMenu', () => {
906
943
flush ( ) ;
907
944
} ) ) ;
908
945
946
+ it ( 'should open submenus when the menu is inside an OnPush component' , fakeAsync ( ( ) => {
947
+ const fixture = createComponent ( LazyMenuWithOnPush ) ;
948
+ fixture . detectChanges ( ) ;
949
+
950
+ // Open the top-level menu
951
+ fixture . componentInstance . rootTrigger . nativeElement . click ( ) ;
952
+ fixture . detectChanges ( ) ;
953
+ flush ( ) ;
954
+
955
+ // Dispatch a `mouseenter` on the menu item to open the submenu.
956
+ // This will only work if the top-level menu is aware the this menu item exists.
957
+ dispatchMouseEvent ( fixture . componentInstance . menuItemWithSubmenu . nativeElement , 'mouseenter' ) ;
958
+ fixture . detectChanges ( ) ;
959
+ flush ( ) ;
960
+
961
+ expect ( overlayContainerElement . querySelectorAll ( '.mat-mdc-menu-item' ) . length )
962
+ . toBe ( 2 , 'Expected two open menus' ) ;
963
+ } ) ) ;
964
+
909
965
it ( 'should focus the menu panel if all items are disabled' , fakeAsync ( ( ) => {
910
966
const fixture = createComponent ( SimpleMenuWithRepeater , [ ] , [ FakeIcon ] ) ;
911
967
fixture . componentInstance . items . forEach ( item => item . disabled = true ) ;
@@ -2588,6 +2644,30 @@ class SimpleMenuWithRepeaterInLazyContent {
2588
2644
}
2589
2645
2590
2646
2647
+ @Component ( {
2648
+ template : `
2649
+ <button [matMenuTriggerFor]="menu" #triggerEl>Toggle menu</button>
2650
+
2651
+ <mat-menu #menu="matMenu">
2652
+ <ng-template matMenuContent>
2653
+ <button [matMenuTriggerFor]="menu2" mat-menu-item #menuItem>Item</button>
2654
+ </ng-template>
2655
+ </mat-menu>
2656
+
2657
+ <mat-menu #menu2="matMenu">
2658
+ <ng-template matMenuContent>
2659
+ <button mat-menu-item #subMenuItem>Sub item</button>
2660
+ </ng-template>
2661
+ </mat-menu>
2662
+ ` ,
2663
+ changeDetection : ChangeDetectionStrategy . OnPush ,
2664
+ } )
2665
+ class LazyMenuWithOnPush {
2666
+ @ViewChild ( 'triggerEl' , { read : ElementRef } ) rootTrigger : ElementRef ;
2667
+ @ViewChild ( 'menuItem' , { read : ElementRef } ) menuItemWithSubmenu : ElementRef ;
2668
+ }
2669
+
2670
+
2591
2671
@Component ( {
2592
2672
template : `
2593
2673
<mat-menu #menu="matMenu">
0 commit comments