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

* fix(overlay): overlay class audits #6372

* chore(nit): pr feedback

* chore(nit): remove param
This commit is contained in:
Austin
2017-10-30 17:06:59 -05:00
committed by mmalerba
parent 1e6762926e
commit cd05b54e37
7 changed files with 42 additions and 6 deletions
+1 -1
View File
@@ -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);
}
@@ -1,5 +1,6 @@
<mat-calendar cdkTrapFocus
[id]="datepicker.id"
[ngClass]="datepicker.panelClass"
[startAt]="datepicker.startAt"
[startView]="datepicker.startView"
[minDate]="datepicker._minDate"
+3
View File
@@ -168,6 +168,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;
+11 -1
View File
@@ -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;
@@ -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() closed = new EventEmitter<void | 'click' | 'keydown'>();
+7 -1
View File
@@ -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';
+18 -2
View File
@@ -104,10 +104,14 @@ export class MatSnackBarContainer extends BasePortalOutlet 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);
}
}
@@ -178,4 +182,16 @@ export class MatSnackBarContainer extends BasePortalOutlet 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 [];
}
}
+1 -1
View File
@@ -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;