Skip to content

Commit 89eff1c

Browse files
committed
feat(menu): add input to add overlay pane classes
1 parent c05a07e commit 89eff1c

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

src/material/menu/menu-panel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export interface MatMenuPanel<T = any> {
3636
setElevation?(depth: number): void;
3737
lazyContent?: MatMenuContent;
3838
backdropClass?: string;
39+
overlayPanelClass?: string|string[];
3940
hasBackdrop?: boolean;
4041
readonly panelId?: string;
4142

src/material/menu/menu-trigger.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
405405
.withLockedPosition()
406406
.withTransformOriginOn('.mat-menu-panel, .mat-mdc-menu-panel'),
407407
backdropClass: this.menu.backdropClass || 'cdk-overlay-transparent-backdrop',
408+
panelClass: this.menu.overlayPanelClass,
408409
scrollStrategy: this._scrollStrategy(),
409410
direction: this._dir
410411
});

src/material/menu/menu.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,36 @@ describe('MatMenu', () => {
245245
expect(backdrop.classList).toContain('custom-backdrop');
246246
}));
247247

248+
fit('should be able to set a custom class on the overlay panel', fakeAsync(() => {
249+
const fixture = createComponent(SimpleMenu, [], [FakeIcon]);
250+
251+
fixture.componentInstance.overlayPanelClass = 'custom-panel-class';
252+
fixture.detectChanges();
253+
fixture.componentInstance.trigger.openMenu();
254+
fixture.detectChanges();
255+
tick(500);
256+
257+
const overlayPane = <HTMLElement>overlayContainerElement.querySelector('.cdk-overlay-pane');
258+
259+
expect(overlayPane.classList).toContain('custom-panel-class');
260+
}));
261+
262+
263+
fit('should be able to set a custom classes on the overlay panel', fakeAsync(() => {
264+
const fixture = createComponent(SimpleMenu, [], [FakeIcon]);
265+
266+
fixture.componentInstance.overlayPanelClass = ['custom-panel-class-1', 'custom-panel-class-2'];
267+
fixture.detectChanges();
268+
fixture.componentInstance.trigger.openMenu();
269+
fixture.detectChanges();
270+
tick(500);
271+
272+
const overlayPane = <HTMLElement>overlayContainerElement.querySelector('.cdk-overlay-pane');
273+
274+
expect(overlayPane.classList).toContain('custom-panel-class-1');
275+
expect(overlayPane.classList).toContain('custom-panel-class-2');
276+
}));
277+
248278
it('should restore focus to the root trigger when the menu was opened by mouse', fakeAsync(() => {
249279
const fixture = createComponent(SimpleMenu, [], [FakeIcon]);
250280
fixture.detectChanges();
@@ -2217,6 +2247,7 @@ describe('MatMenu default overrides', () => {
22172247
[class]="panelClass"
22182248
(closed)="closeCallback($event)"
22192249
[backdropClass]="backdropClass"
2250+
[overlayPanelClass]="overlayPanelClass"
22202251
[aria-label]="ariaLabel"
22212252
[aria-labelledby]="ariaLabelledby"
22222253
[aria-describedby]="ariaDescribedby">
@@ -2239,6 +2270,7 @@ class SimpleMenu {
22392270
extraItems: string[] = [];
22402271
closeCallback = jasmine.createSpy('menu closed callback');
22412272
backdropClass: string;
2273+
overlayPanelClass: string|string[];
22422274
panelClass: string;
22432275
restoreFocus = true;
22442276
ariaLabel: string;

src/material/menu/menu.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ export interface MatMenuDefaultOptions {
6464
/** Class to be applied to the menu's backdrop. */
6565
backdropClass: string;
6666

67+
/** Class or list of classes to be applied to the menu's overlay panel. */
68+
overlayPanelClass: string | string[];
69+
6770
/** Whether the menu has a backdrop. */
6871
hasBackdrop?: boolean;
6972
}
@@ -82,6 +85,7 @@ export function MAT_MENU_DEFAULT_OPTIONS_FACTORY(): MatMenuDefaultOptions {
8285
xPosition: 'after',
8386
yPosition: 'below',
8487
backdropClass: 'cdk-overlay-transparent-backdrop',
88+
overlayPanelClass: '',
8589
};
8690
}
8791
/**
@@ -132,6 +136,9 @@ export class _MatMenuBase implements AfterContentInit, MatMenuPanel<MatMenuItem>
132136
/** Class to be added to the backdrop element. */
133137
@Input() backdropClass: string = this._defaultOptions.backdropClass;
134138

139+
/** Class or list of classes to be added to the overlay panel. */
140+
@Input() overlayPanelClass: string|string[] = this._defaultOptions.overlayPanelClass;
141+
135142
/** aria-label for the menu panel. */
136143
@Input('aria-label') ariaLabel: string;
137144

0 commit comments

Comments
 (0)