Skip to content

Commit cd05b54

Browse files
amcdnlmmalerba
authored andcommitted
fix(overlay): overlay class audits #6372 (#8056)
* fix(overlay): overlay class audits #6372 * chore(nit): pr feedback * chore(nit): remove param
1 parent 1e67629 commit cd05b54

File tree

7 files changed

+42
-6
lines changed

7 files changed

+42
-6
lines changed

src/demo-app/snack-bar/snack-bar-demo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class SnackBarDemo {
3434
config.verticalPosition = this.verticalPosition;
3535
config.horizontalPosition = this.horizontalPosition;
3636
config.duration = this.setAutoHide ? this.autoHide : 0;
37-
config.extraClasses = this.addExtraClass ? ['party'] : undefined;
37+
config.panelClass = this.addExtraClass ? ['party'] : undefined;
3838
config.direction = this.dir.value;
3939
this.snackBar.open(this.message, this.action ? this.actionButtonLabel : undefined, config);
4040
}

src/lib/datepicker/datepicker-content.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<mat-calendar cdkTrapFocus
22
[id]="datepicker.id"
3+
[ngClass]="datepicker.panelClass"
34
[startAt]="datepicker.startAt"
45
[startView]="datepicker.startView"
56
[minDate]="datepicker._minDate"

src/lib/datepicker/datepicker.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ export class MatDatepicker<D> implements OnDestroy {
168168
*/
169169
@Output() selectedChanged = new EventEmitter<D>();
170170

171+
/** Classes to be passed to the date picker panel. Supports the same syntax as `ngClass`. */
172+
@Input() panelClass: string | string[];
173+
171174
/** Whether the calendar is open. */
172175
opened = false;
173176

src/lib/menu/menu-directive.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export class MatMenu implements AfterContentInit, MatMenuPanel, OnDestroy {
129129
* @param classes list of class names
130130
*/
131131
@Input('class')
132-
set classList(classes: string) {
132+
set panelClass(classes: string) {
133133
if (classes && classes.length) {
134134
this._classList = classes.split(' ').reduce((obj: any, className: string) => {
135135
obj[className] = true;
@@ -141,6 +141,16 @@ export class MatMenu implements AfterContentInit, MatMenuPanel, OnDestroy {
141141
}
142142
}
143143

144+
/**
145+
* This method takes classes set on the host mat-menu element and applies them on the
146+
* menu template that displays in the overlay container. Otherwise, it's difficult
147+
* to style the containing menu from outside the component.
148+
* @deprecated Use `panelClass` instead.
149+
*/
150+
@Input()
151+
set classList(classes: string) { this.panelClass = classes; }
152+
get classList(): string { return this.panelClass; }
153+
144154
/** Event emitted when the menu is closed. */
145155
@Output() closed = new EventEmitter<void | 'click' | 'keydown'>();
146156

src/lib/snack-bar/snack-bar-config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ export class MatSnackBarConfig {
3535
duration?: number = 0;
3636

3737
/** Extra CSS classes to be added to the snack bar container. */
38-
extraClasses?: string[];
38+
panelClass?: string | string[];
39+
40+
/**
41+
* Extra CSS classes to be added to the snack bar container.
42+
* @deprecated Use `panelClass` instead.
43+
*/
44+
extraClasses?: string | string[];
3945

4046
/** Text layout direction for the snack bar. */
4147
direction?: Direction = 'ltr';

src/lib/snack-bar/snack-bar-container.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,14 @@ export class MatSnackBarContainer extends BasePortalOutlet implements OnDestroy
104104
throw Error('Attempting to attach snack bar content after content is already attached');
105105
}
106106

107-
if (this.snackBarConfig.extraClasses) {
107+
if (this.snackBarConfig.panelClass || this.snackBarConfig.extraClasses) {
108+
const classes = [
109+
...this._getCssClasses(this.snackBarConfig.panelClass),
110+
...this._getCssClasses(this.snackBarConfig.extraClasses)
111+
];
108112
// Not the most efficient way of adding classes, but the renderer doesn't allow us
109113
// to pass in an array or a space-separated list.
110-
for (let cssClass of this.snackBarConfig.extraClasses) {
114+
for (let cssClass of classes) {
111115
this._renderer.addClass(this._elementRef.nativeElement, cssClass);
112116
}
113117
}
@@ -178,4 +182,16 @@ export class MatSnackBarContainer extends BasePortalOutlet implements OnDestroy
178182
this._onExit.complete();
179183
});
180184
}
185+
186+
/** Convert the class list to a array of classes it can apply to the dom */
187+
private _getCssClasses(classList: undefined | string | string[]) {
188+
if (classList) {
189+
if (Array.isArray(classList)) {
190+
return classList;
191+
} else {
192+
return [classList];
193+
}
194+
}
195+
return [];
196+
}
181197
}

src/lib/snack-bar/snack-bar.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ describe('MatSnackBar', () => {
363363
}));
364364

365365
it('should add extra classes to the container', () => {
366-
snackBar.open(simpleMessage, simpleActionLabel, { extraClasses: ['one', 'two'] });
366+
snackBar.open(simpleMessage, simpleActionLabel, { panelClass: ['one', 'two'] });
367367
viewContainerFixture.detectChanges();
368368

369369
let containerClasses = overlayContainerElement.querySelector('snack-bar-container')!.classList;

0 commit comments

Comments
 (0)