From c101f7ff75acdd624e1e599f1f33a67252e36558 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Green Date: Fri, 25 Dec 2020 16:15:01 +0100 Subject: [PATCH 1/2] fix(material/dialog): make align attribute into an input of dialog actions directive instead of css Fixes multiple issues, such as self-documentation of the align attribute, type checking, better bindings, and IDE support. Because align is not standard for HTMLDivElement, it doesn't make much sense to assume end users to know they can use the align attribute. Fixes #18479 --- src/dev-app/dialog/dialog-demo.ts | 18 +++++++-------- .../dialog/dialog-content-directives.ts | 22 ++++++++++++------- src/material/dialog/dialog.scss | 11 +++++----- src/material/dialog/dialog.spec.ts | 12 ++++++++-- 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/src/dev-app/dialog/dialog-demo.ts b/src/dev-app/dialog/dialog-demo.ts index 5223f841c918..7a28213edfad 100644 --- a/src/dev-app/dialog/dialog-demo.ts +++ b/src/dev-app/dialog/dialog-demo.ts @@ -22,7 +22,7 @@ export class DialogDemo { dialogRef: MatDialogRef | null; lastAfterClosedResult: string; lastBeforeCloseResult: string; - actionsAlignment: string; + actionsAlignment: 'end' | 'center' | undefined; config = { disableClose: false, panelClass: 'custom-overlay-pane-class', @@ -110,20 +110,20 @@ export class JazzDialog { private _dimesionToggle = false; constructor( - public dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public data: any) { } + public dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data: any) { } togglePosition(): void { this._dimesionToggle = !this._dimesionToggle; if (this._dimesionToggle) { this.dialogRef - .updateSize('500px', '500px') - .updatePosition({ top: '25px', left: '25px' }); + .updateSize('500px', '500px') + .updatePosition({ top: '25px', left: '25px' }); } else { this.dialogRef - .updateSize() - .updatePosition(); + .updateSize() + .updatePosition(); } } @@ -160,7 +160,7 @@ export class JazzDialog {

- + '}) +@Component({template : '

Pizza

'}) class PizzaMsg { - constructor( - public dialogRef: MatDialogRef, public dialogInjector: Injector, - public directionality: Directionality) {} + constructor(public dialogRef: MatDialogRef, public dialogInjector: Injector, + public directionality: Directionality) {} } @Component({ - template: ` + template : `

This is the title

Lorem ipsum dolor sit amet. - + '}) +@Component({template : '

Pizza

'}) class PizzaMsg { - constructor(public dialogRef: MatDialogRef, - public dialogInjector: Injector, + constructor(public dialogRef: MatDialogRef, public dialogInjector: Injector, public directionality: Directionality) {} } @Component({ - template: ` + template : `

This is the title

Lorem ipsum dolor sit amet. @@ -1896,10 +1799,11 @@ class PizzaMsg { ` }) -class ContentElementDialog {} +class ContentElementDialog { +} @Component({ - template: ` + template : `

This is the title

Lorem ipsum dolor sit amet. @@ -1920,22 +1824,20 @@ class ComponentWithContentElementTemplateRef { @ViewChild(TemplateRef) templateRef: TemplateRef; } -@Component({ - template: '', - providers: [MatDialog] -}) +@Component({template : '', providers : [ MatDialog ]}) class ComponentThatProvidesMatDialog { constructor(public dialog: MatDialog) {} } /** Simple component for testing ComponentPortal. */ -@Component({template: ''}) +@Component({template : ''}) class DialogWithInjectedData { - constructor(@Inject(MAT_DIALOG_DATA) public data: any) { } + constructor(@Inject(MAT_DIALOG_DATA) public data: any) {} } -@Component({template: '

Pasta

'}) -class DialogWithoutFocusableElements {} +@Component({template : '

Pasta

'}) +class DialogWithoutFocusableElements { +} // Create a real (non-test) NgModule as a workaround for // https://github.com/angular/angular/issues/10760 @@ -1952,10 +1854,10 @@ const TEST_DIRECTIVES = [ ]; @NgModule({ - imports: [MatDialogModule, NoopAnimationsModule], - exports: TEST_DIRECTIVES, - declarations: TEST_DIRECTIVES, - entryComponents: [ + imports : [ MatDialogModule, NoopAnimationsModule ], + exports : TEST_DIRECTIVES, + declarations : TEST_DIRECTIVES, + entryComponents : [ ComponentWithChildViewContainer, ComponentWithTemplateRef, PizzaMsg, @@ -1964,4 +1866,5 @@ const TEST_DIRECTIVES = [ DialogWithoutFocusableElements, ], }) -class DialogTestModule { } +class DialogTestModule { +} diff --git a/tools/public_api_guard/material/dialog.d.ts b/tools/public_api_guard/material/dialog.d.ts index 52dd272a5bfe..6f952a3de2d0 100644 --- a/tools/public_api_guard/material/dialog.d.ts +++ b/tools/public_api_guard/material/dialog.d.ts @@ -74,7 +74,8 @@ export declare class MatDialog extends _MatDialogBase { } export declare class MatDialogActions { - static ɵdir: i0.ɵɵDirectiveDefWithMeta; + align?: 'center' | 'end'; + static ɵdir: i0.ɵɵDirectiveDefWithMeta; static ɵfac: i0.ɵɵFactoryDef; }