Skip to content

Commit d7c734c

Browse files
jianliaojelbourn
authored andcommitted
feat(overlay): support setting panelClass on cdkConnectedOverlay (#12380)
1 parent 3b7f0f1 commit d7c734c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/cdk/overlay/overlay-directives.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,15 @@ describe('Overlay directives', () => {
232232
expect(backdrop.classList).toContain('mat-test-class');
233233
});
234234

235+
it('should set the custom panel class', () => {
236+
fixture.componentInstance.isOpen = true;
237+
fixture.detectChanges();
238+
239+
const panel
240+
= overlayContainerElement.querySelector('.cdk-overlay-pane') as HTMLElement;
241+
expect(panel.classList).toContain('cdk-test-panel-class');
242+
});
243+
235244
it('should set the offsetX', () => {
236245
fixture.componentInstance.offsetX = 5;
237246
fixture.componentInstance.isOpen = true;
@@ -478,6 +487,7 @@ describe('Overlay directives', () => {
478487
[cdkConnectedOverlayGrowAfterOpen]="growAfterOpen"
479488
[cdkConnectedOverlayPush]="push"
480489
cdkConnectedOverlayBackdropClass="mat-test-class"
490+
cdkConnectedOverlayPanelClass="cdk-test-panel-class"
481491
(backdropClick)="backdropClickHandler($event)"
482492
[cdkConnectedOverlayOffsetX]="offsetX"
483493
[cdkConnectedOverlayOffsetY]="offsetY"

src/cdk/overlay/overlay-directives.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
158158
/** The custom class to be set on the backdrop element. */
159159
@Input('cdkConnectedOverlayBackdropClass') backdropClass: string;
160160

161+
/** The custom class to add to the overlay pane element. */
162+
@Input('cdkConnectedOverlayPanelClass') panelClass: string | string[];
163+
161164
/** Margin between the overlay and the viewport edges. */
162165
@Input('cdkConnectedOverlayViewportMargin') viewportMargin: number = 0;
163166

@@ -296,6 +299,10 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
296299
overlayConfig.backdropClass = this.backdropClass;
297300
}
298301

302+
if (this.panelClass) {
303+
overlayConfig.panelClass = this.panelClass;
304+
}
305+
299306
return overlayConfig;
300307
}
301308

0 commit comments

Comments
 (0)