Skip to content

Commit 987c85d

Browse files
crisbetojelbourn
authored andcommitted
fix(menu): cap maximum elevation for nested menus (#17687)
Currently we increase the elevation of each nested menu by one, however we don't have an upper limit which means that menus 20 levels down won't have any elevation (the elevation starts at 4). This is a bit of an edge case since opening 20 menus is a lot, but it's easy to handle on our end.
1 parent b622d11 commit 987c85d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/material/menu/menu.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,9 @@ export class _MatMenuBase implements AfterContentInit, MatMenuPanel<MatMenuItem>
374374
*/
375375
setElevation(depth: number): void {
376376
// The elevation starts at the base and increases by one for each level.
377-
const newElevation = `mat-elevation-z${MAT_MENU_BASE_ELEVATION + depth}`;
377+
// Capped at 24 because that's the maximum elevation defined in the Material design spec.
378+
const elevation = Math.min(MAT_MENU_BASE_ELEVATION + depth, 24);
379+
const newElevation = `mat-elevation-z${elevation}`;
378380
const customElevation = Object.keys(this._classList).find(c => c.startsWith('mat-elevation-z'));
379381

380382
if (!customElevation || customElevation === this._previousElevation) {

0 commit comments

Comments
 (0)