@@ -532,6 +532,29 @@ describe('MDC-based MatMenu', () => {
532
532
expect ( panel . classList ) . toContain ( 'custom-two' ) ;
533
533
} ) ;
534
534
535
+ it ( 'should not remove mat-elevation class from overlay when panelClass is changed' , ( ) => {
536
+ const fixture = createComponent ( SimpleMenu , [ ] , [ FakeIcon ] ) ;
537
+
538
+ fixture . componentInstance . panelClass = 'custom-one' ;
539
+ fixture . detectChanges ( ) ;
540
+ fixture . componentInstance . trigger . openMenu ( ) ;
541
+ fixture . detectChanges ( ) ;
542
+
543
+ const panel = overlayContainerElement . querySelector ( '.mat-mdc-menu-panel' ) ! ;
544
+
545
+ expect ( panel . classList ) . toContain ( 'custom-one' ) ;
546
+ expect ( panel . classList ) . toContain ( 'mat-mdc-elevation-z8' ) ;
547
+
548
+ fixture . componentInstance . panelClass = 'custom-two' ;
549
+ fixture . detectChanges ( ) ;
550
+
551
+ expect ( panel . classList ) . not . toContain ( 'custom-one' ) ;
552
+ expect ( panel . classList ) . toContain ( 'custom-two' ) ;
553
+ expect ( panel . classList ) . toContain ( 'mat-mdc-elevation-specific' ) ;
554
+ expect ( panel . classList )
555
+ . toContain ( 'mat-mdc-elevation-z8' , 'Expected mat-mdc-elevation-z8 not to be removed' ) ;
556
+ } ) ;
557
+
535
558
it ( 'should set the "menu" role on the overlay panel' , ( ) => {
536
559
const fixture = createComponent ( SimpleMenu , [ ] , [ FakeIcon ] ) ;
537
560
fixture . detectChanges ( ) ;
@@ -2050,6 +2073,70 @@ describe('MDC-based MatMenu', () => {
2050
2073
expect ( menuItems [ 1 ] . classList ) . not . toContain ( 'mat-mdc-menu-item-submenu-trigger' ) ;
2051
2074
} ) ;
2052
2075
2076
+ it ( 'should increase the sub-menu elevation based on its depth' , ( ) => {
2077
+ compileTestComponent ( ) ;
2078
+ instance . rootTrigger . openMenu ( ) ;
2079
+ fixture . detectChanges ( ) ;
2080
+
2081
+ instance . levelOneTrigger . openMenu ( ) ;
2082
+ fixture . detectChanges ( ) ;
2083
+
2084
+ instance . levelTwoTrigger . openMenu ( ) ;
2085
+ fixture . detectChanges ( ) ;
2086
+
2087
+ const menus = overlay . querySelectorAll ( '.mat-mdc-menu-panel' ) ;
2088
+
2089
+ expect ( menus [ 0 ] . classList ) . toContain ( 'mat-mdc-elevation-specific' ) ;
2090
+ expect ( menus [ 0 ] . classList )
2091
+ . toContain ( 'mat-mdc-elevation-z8' , 'Expected root menu to have base elevation.' ) ;
2092
+
2093
+ expect ( menus [ 1 ] . classList ) . toContain ( 'mat-mdc-elevation-specific' ) ;
2094
+ expect ( menus [ 1 ] . classList )
2095
+ . toContain ( 'mat-mdc-elevation-z9' , 'Expected first sub-menu to have base elevation + 1.' ) ;
2096
+
2097
+ expect ( menus [ 2 ] . classList ) . toContain ( 'mat-mdc-elevation-specific' ) ;
2098
+ expect ( menus [ 2 ] . classList )
2099
+ . toContain ( 'mat-mdc-elevation-z10' , 'Expected second sub-menu to have base elevation + 2.' ) ;
2100
+ } ) ;
2101
+
2102
+ it ( 'should update the elevation when the same menu is opened at a different depth' ,
2103
+ fakeAsync ( ( ) => {
2104
+ compileTestComponent ( ) ;
2105
+ instance . rootTrigger . openMenu ( ) ;
2106
+ fixture . detectChanges ( ) ;
2107
+
2108
+ instance . levelOneTrigger . openMenu ( ) ;
2109
+ fixture . detectChanges ( ) ;
2110
+
2111
+ instance . levelTwoTrigger . openMenu ( ) ;
2112
+ fixture . detectChanges ( ) ;
2113
+
2114
+ let lastMenu = overlay . querySelectorAll ( '.mat-mdc-menu-panel' ) [ 2 ] ;
2115
+
2116
+ expect ( lastMenu . classList ) . toContain ( 'mat-mdc-elevation-specific' ) ;
2117
+ expect ( lastMenu . classList )
2118
+ . toContain ( 'mat-mdc-elevation-z10' , 'Expected menu to have the base elevation plus two.' ) ;
2119
+
2120
+ ( overlay . querySelector ( '.cdk-overlay-backdrop' ) ! as HTMLElement ) . click ( ) ;
2121
+ fixture . detectChanges ( ) ;
2122
+ tick ( 500 ) ;
2123
+
2124
+ expect ( overlay . querySelectorAll ( '.mat-mdc-menu-panel' ) . length )
2125
+ . toBe ( 0 , 'Expected no open menus' ) ;
2126
+
2127
+ instance . alternateTrigger . openMenu ( ) ;
2128
+ fixture . detectChanges ( ) ;
2129
+ tick ( 500 ) ;
2130
+
2131
+ lastMenu = overlay . querySelector ( '.mat-mdc-menu-panel' ) as HTMLElement ;
2132
+
2133
+ expect ( lastMenu . classList ) . toContain ( 'mat-mdc-elevation-specific' ) ;
2134
+ expect ( lastMenu . classList ) . not . toContain ( 'mat-mdc-elevation-z10' ,
2135
+ 'Expected menu not to maintain old elevation.' ) ;
2136
+ expect ( lastMenu . classList ) . toContain ( 'mat-mdc-elevation-z8' ,
2137
+ 'Expected menu to have the proper updated elevation.' ) ;
2138
+ } ) ) ;
2139
+
2053
2140
it ( 'should not change focus origin if origin not specified for trigger' , fakeAsync ( ( ) => {
2054
2141
compileTestComponent ( ) ;
2055
2142
@@ -2067,6 +2154,26 @@ describe('MDC-based MatMenu', () => {
2067
2154
expect ( levelTwoTrigger . classList ) . toContain ( 'cdk-mouse-focused' ) ;
2068
2155
} ) ) ;
2069
2156
2157
+ it ( 'should not increase the elevation if the user specified a custom one' , ( ) => {
2158
+ const elevationFixture = createComponent ( NestedMenuCustomElevation ) ;
2159
+
2160
+ elevationFixture . detectChanges ( ) ;
2161
+ elevationFixture . componentInstance . rootTrigger . openMenu ( ) ;
2162
+ elevationFixture . detectChanges ( ) ;
2163
+
2164
+ elevationFixture . componentInstance . levelOneTrigger . openMenu ( ) ;
2165
+ elevationFixture . detectChanges ( ) ;
2166
+
2167
+ const menuClasses =
2168
+ overlayContainerElement . querySelectorAll ( '.mat-mdc-menu-panel' ) [ 1 ] . classList ;
2169
+
2170
+ expect ( menuClasses ) . toContain ( 'mat-mdc-elevation-specific' ) ;
2171
+ expect ( menuClasses )
2172
+ . toContain ( 'mat-mdc-elevation-z24' , 'Expected user elevation to be maintained' ) ;
2173
+ expect ( menuClasses )
2174
+ . not . toContain ( 'mat-mdc-elevation-z8' , 'Expected no stacked elevation.' ) ;
2175
+ } ) ;
2176
+
2070
2177
it ( 'should close all of the menus when the root is closed programmatically' , fakeAsync ( ( ) => {
2071
2178
compileTestComponent ( ) ;
2072
2179
instance . rootTrigger . openMenu ( ) ;
@@ -2487,6 +2594,26 @@ class NestedMenu {
2487
2594
showLazy = false ;
2488
2595
}
2489
2596
2597
+ @Component ( {
2598
+ template : `
2599
+ <button [matMenuTriggerFor]="root" #rootTrigger="matMenuTrigger">Toggle menu</button>
2600
+
2601
+ <mat-menu #root="matMenu">
2602
+ <button mat-menu-item
2603
+ [matMenuTriggerFor]="levelOne"
2604
+ #levelOneTrigger="matMenuTrigger">One</button>
2605
+ </mat-menu>
2606
+
2607
+ <mat-menu #levelOne="matMenu" class="mat-mdc-elevation-z24">
2608
+ <button mat-menu-item>Two</button>
2609
+ </mat-menu>
2610
+ `
2611
+ } )
2612
+ class NestedMenuCustomElevation {
2613
+ @ViewChild ( 'rootTrigger' ) rootTrigger : MatMenuTrigger ;
2614
+ @ViewChild ( 'levelOneTrigger' ) levelOneTrigger : MatMenuTrigger ;
2615
+ }
2616
+
2490
2617
2491
2618
@Component ( {
2492
2619
template : `
0 commit comments