Skip to content

fix(overlay): overlay class audits #6372 #8056

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/demo-app/snack-bar/snack-bar-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class SnackBarDemo {
config.verticalPosition = this.verticalPosition;
config.horizontalPosition = this.horizontalPosition;
config.duration = this.setAutoHide ? this.autoHide : 0;
config.extraClasses = this.addExtraClass ? ['party'] : undefined;
config.panelClass = this.addExtraClass ? ['party'] : undefined;
config.direction = this.dir.value;
this.snackBar.open(this.message, this.action ? this.actionButtonLabel : undefined, config);
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/datepicker/datepicker-content.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<mat-calendar cdkTrapFocus
[id]="datepicker.id"
[ngClass]="datepicker.panelClass"
[startAt]="datepicker.startAt"
[startView]="datepicker.startView"
[minDate]="datepicker._minDate"
Expand Down
3 changes: 3 additions & 0 deletions src/lib/datepicker/datepicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ export class MatDatepicker<D> implements OnDestroy {
*/
@Output() selectedChanged = new EventEmitter<D>();

/** Classes to be passed to the date picker panel. Supports the same syntax as `ngClass`. */
@Input() panelClass: string | string[];

/** Whether the calendar is open. */
opened = false;

Expand Down
12 changes: 11 additions & 1 deletion src/lib/menu/menu-directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class MatMenu implements AfterContentInit, MatMenuPanel, OnDestroy {
* @param classes list of class names
*/
@Input('class')
set classList(classes: string) {
set panelClass(classes: string) {
if (classes && classes.length) {
this._classList = classes.split(' ').reduce((obj: any, className: string) => {
obj[className] = true;
Expand All @@ -141,6 +141,16 @@ export class MatMenu implements AfterContentInit, MatMenuPanel, OnDestroy {
}
}

/**
* This method takes classes set on the host mat-menu element and applies them on the
* menu template that displays in the overlay container. Otherwise, it's difficult
* to style the containing menu from outside the component.
* @deprecated Use `panelClass` instead.
*/
@Input()
set classList(classes: string) { this.panelClass = classes; }
get classList(): string { return this.panelClass; }

/** Event emitted when the menu is closed. */
@Output() close = new EventEmitter<void | 'click' | 'keydown'>();

Expand Down
8 changes: 7 additions & 1 deletion src/lib/snack-bar/snack-bar-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ export class MatSnackBarConfig {
duration?: number = 0;

/** Extra CSS classes to be added to the snack bar container. */
extraClasses?: string[];
panelClass?: string | string[];

/**
* Extra CSS classes to be added to the snack bar container.
* @deprecated Use `panelClass` instead.
*/
extraClasses?: string | string[];

/** Text layout direction for the snack bar. */
direction?: Direction = 'ltr';
Expand Down
20 changes: 18 additions & 2 deletions src/lib/snack-bar/snack-bar-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,14 @@ export class MatSnackBarContainer extends BasePortalHost implements OnDestroy {
throw Error('Attempting to attach snack bar content after content is already attached');
}

if (this.snackBarConfig.extraClasses) {
if (this.snackBarConfig.panelClass || this.snackBarConfig.extraClasses) {
const classes = [
...this._getCssClasses(this.snackBarConfig.panelClass),
...this._getCssClasses(this.snackBarConfig.extraClasses)
];
// Not the most efficient way of adding classes, but the renderer doesn't allow us
// to pass in an array or a space-separated list.
for (let cssClass of this.snackBarConfig.extraClasses) {
for (let cssClass of classes) {
this._renderer.addClass(this._elementRef.nativeElement, cssClass);
}
}
Expand Down Expand Up @@ -178,4 +182,16 @@ export class MatSnackBarContainer extends BasePortalHost implements OnDestroy {
this._onExit.complete();
});
}

/** Convert the class list to a array of classes it can apply to the dom */
private _getCssClasses(classList: undefined | string | string[]) {
if (classList) {
if (Array.isArray(classList)) {
return classList;
} else {
return [classList];
}
}
return [];
}
}
2 changes: 1 addition & 1 deletion src/lib/snack-bar/snack-bar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ describe('MatSnackBar', () => {
}));

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

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