Skip to content

Commit d7a9cbb

Browse files
PooShamdevversion
authored andcommitted
fix(material/dialog): Use align as @input() in MatDialogActions
Squashed commit of the following: commit 1d6daeadf8e06e38c64fec724d5a8d2899b502d3 Merge: 3276432 3a98da8 Author: Jean-Philippe Green <[email protected]> Date: Mon Jan 31 19:24:24 2022 +0100 Merge branch 'master' into align-attr-as-input-in-dialog-actions-#18479-2 commit 3276432 Merge: 815cf8f 1f40b7d Author: Jean-Philippe <[email protected]> Date: Mon Jan 31 18:54:42 2022 +0100 Merge branch 'angular:master' into align-attr-as-input-in-dialog-actions-#18479-2 commit 815cf8f Author: Jean-Philippe Green <[email protected]> Date: Mon Jan 10 01:23:12 2022 +0100 Use directive binding in mdc-dialog demo for align commit 77fca70 Author: Jean-Philippe Green <[email protected]> Date: Mon Jan 10 01:20:43 2022 +0100 Change actionsAlignment type in dialog demo commit c87c4aa Author: Jean-Philippe Green <[email protected]> Date: Mon Jan 10 00:21:57 2022 +0100 Revert weird changes to dialog.spec.ts commit d6deb45 Author: Jean-Philippe <[email protected]> Date: Sun Jan 9 23:30:24 2022 +0100 Use 'start' as default instead of undefined for align attribute in dialog actions commit 8d367c1 Author: Jean-Philippe <[email protected]> Date: Sun Jan 9 23:05:54 2022 +0100 Update comments in dialog.scss for more clarity commit 9d2ac16 Merge: 54d0a60 3de4ab8 Author: Jean-Philippe <[email protected]> Date: Sun Jan 9 22:33:13 2022 +0100 Merge branch 'angular:master' into align-attr-as-input-in-dialog-actions-#18479 commit 54d0a60 Merge: 462d407 c79e1d1 Author: Jean-Philippe Green <[email protected]> Date: Wed Jan 5 21:30:29 2022 +0100 Merge branch 'angular-master' into align-attr-as-input-in-dialog-actions-#18479 commit c79e1d1 Merge: 462d407 03485cd Author: Jean-Philippe Green <[email protected]> Date: Wed Jan 5 21:23:17 2022 +0100 Merge branch 'master' of https://github.com/angular/components into angular-master commit 462d407 Author: Jean-Philippe Green <[email protected]> Date: Fri Dec 25 16:18:08 2020 +0100 fix(material-experimental/mdc-dialog): make align attr into an input of dialog actions directive 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 for material-experimental commit c101f7f Author: Jean-Philippe Green <[email protected]> Date: Fri Dec 25 16:15:01 2020 +0100 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
1 parent a74d92e commit d7a9cbb

File tree

8 files changed

+61
-24
lines changed

8 files changed

+61
-24
lines changed

src/dev-app/dialog/dialog-demo.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class DialogDemo {
2121
dialogRef: MatDialogRef<JazzDialog> | null;
2222
lastAfterClosedResult: string;
2323
lastBeforeCloseResult: string;
24-
actionsAlignment: string;
24+
actionsAlignment: 'start' | 'center' | 'end';
2525
config = {
2626
disableClose: false,
2727
panelClass: 'custom-overlay-pane-class',
@@ -156,7 +156,7 @@ export class JazzDialog {
156156
</p>
157157
</mat-dialog-content>
158158
159-
<mat-dialog-actions [attr.align]="actionsAlignment">
159+
<mat-dialog-actions [align]="actionsAlignment">
160160
<button
161161
mat-raised-button
162162
color="primary"
@@ -177,7 +177,7 @@ export class JazzDialog {
177177
`,
178178
})
179179
export class ContentElementDialog {
180-
actionsAlignment: string;
180+
actionsAlignment: 'start' | 'center' | 'end';
181181

182182
constructor(public dialog: MatDialog) {}
183183

src/dev-app/mdc-dialog/mdc-dialog-demo.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class DialogDemo {
2929
dialogRef: MatDialogRef<JazzDialog> | null;
3030
lastAfterClosedResult: string;
3131
lastBeforeCloseResult: string;
32-
actionsAlignment: string;
32+
actionsAlignment: 'start' | 'center' | 'end';
3333
config = {
3434
disableClose: false,
3535
panelClass: 'custom-overlay-pane-class',
@@ -173,7 +173,7 @@ export class JazzDialog {
173173
</p>
174174
</mat-dialog-content>
175175
176-
<mat-dialog-actions [attr.align]="actionsAlignment">
176+
<mat-dialog-actions [align]="actionsAlignment">
177177
<button
178178
mat-raised-button
179179
color="primary"
@@ -194,7 +194,7 @@ export class JazzDialog {
194194
`,
195195
})
196196
export class ContentElementDialog {
197-
actionsAlignment: string;
197+
actionsAlignment: 'start' | 'center' | 'end';
198198

199199
constructor(public dialog: MatDialog) {}
200200

src/material-experimental/mdc-dialog/dialog-content-directives.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,15 @@ export class MatDialogContent {}
141141
*/
142142
@Directive({
143143
selector: `[mat-dialog-actions], mat-dialog-actions, [matDialogActions]`,
144-
host: {'class': 'mat-mdc-dialog-actions mdc-dialog__actions'},
144+
host: {
145+
'class': 'mat-mdc-dialog-actions mdc-dialog__actions',
146+
'[class.mat-mdc-dialog-actions-align-center]': 'align === "center"',
147+
'[class.mat-mdc-dialog-actions-align-end]': 'align === "end"',
148+
},
145149
})
146-
export class MatDialogActions {}
150+
export class MatDialogActions {
151+
@Input() align?: 'start' | 'center' | 'end' = 'start';
152+
}
147153

148154
/**
149155
* Finds the closest MatDialogRef to an element by looking at the DOM.

src/material-experimental/mdc-dialog/dialog.scss

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ $mat-dialog-button-horizontal-margin: 8px !default;
2929
// aligns actions at the end of the container.
3030
justify-content: start;
3131

32-
&[align='end'] {
33-
justify-content: flex-end;
34-
}
35-
36-
&[align='center'] {
32+
// .mat-mdc-dialog-actions-align-{center|end} are set by directive input "align"
33+
// [align='center'] and [align='right'] are kept for backwards compability
34+
&.mat-mdc-dialog-actions-align-center, &[align='center'] {
3735
justify-content: center;
3836
}
37+
&.mat-mdc-dialog-actions-align-end, &[align='end'] {
38+
justify-content: flex-end;
39+
}
3940

4041
// MDC applies horizontal margin to buttons that have an explicit `mdc-dialog__button`
4142
// class applied. We can't set this class for projected buttons that consumers of the

src/material-experimental/mdc-dialog/dialog.spec.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,6 +1670,17 @@ describe('MDC-based MatDialog', () => {
16701670
.withContext('Expected the aria-labelledby to match the title id.')
16711671
.toBe(title.id);
16721672
}));
1673+
1674+
it('should add mat-mdc-dialog-actions-align-* class according to given [align] input in [mat-dialog-actions]', () => {
1675+
let actions = overlayContainerElement.querySelector('mat-dialog-actions')!;
1676+
1677+
expect(actions)
1678+
.withContext('Expected action buttons to not have class align-center')
1679+
.not.toHaveClass('mat-mdc-dialog-actions-align-center');
1680+
expect(actions)
1681+
.withContext('Expected action buttons to have class align-end')
1682+
.not.toHaveClass('mat-mdc-dialog-actions-align-end');
1683+
});
16731684
}
16741685
});
16751686

@@ -2072,7 +2083,7 @@ class PizzaMsg {
20722083
template: `
20732084
<h1 mat-dialog-title>This is the title</h1>
20742085
<mat-dialog-content>Lorem ipsum dolor sit amet.</mat-dialog-content>
2075-
<mat-dialog-actions>
2086+
<mat-dialog-actions align="end">
20762087
<button mat-dialog-close>Close</button>
20772088
<button class="close-with-true" [mat-dialog-close]="true">Close and return true</button>
20782089
<button
@@ -2091,7 +2102,7 @@ class ContentElementDialog {}
20912102
<ng-template>
20922103
<h1 mat-dialog-title>This is the title</h1>
20932104
<mat-dialog-content>Lorem ipsum dolor sit amet.</mat-dialog-content>
2094-
<mat-dialog-actions>
2105+
<mat-dialog-actions align="end">
20952106
<button mat-dialog-close>Close</button>
20962107
<button class="close-with-true" [mat-dialog-close]="true">Close and return true</button>
20972108
<button

src/material/dialog/dialog-content-directives.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,15 @@ export class MatDialogContent {}
145145
*/
146146
@Directive({
147147
selector: `[mat-dialog-actions], mat-dialog-actions, [matDialogActions]`,
148-
host: {'class': 'mat-dialog-actions'},
148+
host: {
149+
'class': 'mat-dialog-actions',
150+
'[class.mat-dialog-actions-align-center]': 'align === "center"',
151+
'[class.mat-dialog-actions-align-end]': 'align === "end"',
152+
},
149153
})
150-
export class MatDialogActions {}
154+
export class MatDialogActions {
155+
@Input() align?: 'start' | 'center' | 'end' = 'start';
156+
}
151157

152158
/**
153159
* Finds the closest MatDialogRef to an element by looking at the DOM.

src/material/dialog/dialog.scss

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,14 @@ $button-margin: 8px !default;
5656
// Pull the actions down to avoid their padding stacking with the dialog's padding.
5757
margin-bottom: -$padding;
5858

59-
&[align='end'] {
60-
justify-content: flex-end;
61-
}
62-
63-
&[align='center'] {
59+
// .mat-dialog-actions-align-{center|end} are set by directive input "align"
60+
// [align='center'] and [align='right'] are kept for backwards compability
61+
&.mat-dialog-actions-align-center, &[align='center'] {
6462
justify-content: center;
6563
}
64+
&.mat-dialog-actions-align-end, &[align='end'] {
65+
justify-content: flex-end;
66+
}
6667

6768
.mat-button-base + .mat-button-base,
6869
.mat-mdc-button-base + .mat-mdc-button-base {

src/material/dialog/dialog.spec.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,6 +1733,18 @@ describe('MatDialog', () => {
17331733
.withContext('Expected the aria-labelledby to match the title id.')
17341734
.toBe(title.id);
17351735
}));
1736+
1737+
it('should add mat-dialog-actions-align-* class according to given [align] input in [mat-dialog-actions]', () => {
1738+
let actions = overlayContainerElement.querySelector('mat-dialog-actions')!;
1739+
1740+
expect(actions)
1741+
.withContext('Expected action buttons to not have class mat-dialog-actions-align-center')
1742+
.not.toHaveClass('mat-dialog-actions-align-center');
1743+
1744+
expect(actions)
1745+
.withContext('Expected action buttons to have class mat-dialog-actions-align-end')
1746+
.toHaveClass('mat-dialog-actions-align-end');
1747+
});
17361748
}
17371749
});
17381750

@@ -2116,7 +2128,7 @@ class PizzaMsg {
21162128
template: `
21172129
<h1 mat-dialog-title>This is the title</h1>
21182130
<mat-dialog-content>Lorem ipsum dolor sit amet.</mat-dialog-content>
2119-
<mat-dialog-actions>
2131+
<mat-dialog-actions align="end">
21202132
<button mat-dialog-close>Close</button>
21212133
<button class="close-with-true" [mat-dialog-close]="true">Close and return true</button>
21222134
<button
@@ -2135,7 +2147,7 @@ class ContentElementDialog {}
21352147
<ng-template>
21362148
<h1 mat-dialog-title>This is the title</h1>
21372149
<mat-dialog-content>Lorem ipsum dolor sit amet.</mat-dialog-content>
2138-
<mat-dialog-actions>
2150+
<mat-dialog-actions align="end">
21392151
<button mat-dialog-close>Close</button>
21402152
<button class="close-with-true" [mat-dialog-close]="true">Close and return true</button>
21412153
<button

0 commit comments

Comments
 (0)