Skip to content

Commit 7b51418

Browse files
committed
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
1 parent c101f7f commit 7b51418

File tree

5 files changed

+916
-1000
lines changed

5 files changed

+916
-1000
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,13 @@ export class MatDialogContent {
139139
*/
140140
@Directive({
141141
selector: `[mat-dialog-actions], mat-dialog-actions, [matDialogActions]`,
142-
host: {'class': 'mat-mdc-dialog-actions mdc-dialog__actions'}
142+
host: {
143+
'class': 'mat-mdc-dialog-actions mdc-dialog__actions',
144+
'[class.mat-mdc-dialog-actions-align-center]': 'align === "center"',
145+
'[class.mat-mdc-dialog-actions-align-end]': 'align === "end"'}
143146
})
144147
export class MatDialogActions {
148+
@Input() align?: 'center' | 'end' = undefined;
145149
}
146150

147151

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

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

37-
&[align='end'] {
38-
justify-content: flex-end;
39-
}
40-
41-
&[align='center'] {
37+
// .align-center and .align-end are set by directive input "align"
38+
&.mat-mdc-dialog-actions-align-center {
4239
justify-content: center;
4340
}
41+
&.mat-mdc-dialog-actions-align-end {
42+
justify-content: flex-end;
43+
}
4444

4545
// MDC applies horizontal margin to buttons that have an explicit `mdc-dialog__button`
4646
// 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: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,14 @@ describe('MDC-based MatDialog', () => {
14081408
expect(container.getAttribute('aria-labelledby'))
14091409
.toBe(title.id, 'Expected the aria-labelledby to match the title id.');
14101410
}));
1411+
1412+
it('should add align-* class according to given [align] input in [mat-dialog-actions]', () => {
1413+
let actions =
1414+
overlayContainerElement.querySelector('mat-dialog-actions')!;
1415+
1416+
expect(actions).not.toHaveClass('mat-mdc-dialog-actions-align-center', 'Expected action buttons to not have class align-center');
1417+
expect(actions).toHaveClass('mat-mdc-dialog-actions-align-end', 'Expected action buttons to have class align-end');
1418+
});
14111419
}
14121420
});
14131421

@@ -1800,7 +1808,7 @@ class PizzaMsg {
18001808
template: `
18011809
<h1 mat-dialog-title>This is the title</h1>
18021810
<mat-dialog-content>Lorem ipsum dolor sit amet.</mat-dialog-content>
1803-
<mat-dialog-actions>
1811+
<mat-dialog-actions align="end">
18041812
<button mat-dialog-close>Close</button>
18051813
<button class="close-with-true" [mat-dialog-close]="true">Close and return true</button>
18061814
<button
@@ -1820,7 +1828,7 @@ class ContentElementDialog {
18201828
<ng-template>
18211829
<h1 mat-dialog-title>This is the title</h1>
18221830
<mat-dialog-content>Lorem ipsum dolor sit amet.</mat-dialog-content>
1823-
<mat-dialog-actions>
1831+
<mat-dialog-actions align="end">
18241832
<button mat-dialog-close>Close</button>
18251833
<button class="close-with-true" [mat-dialog-close]="true">Close and return true</button>
18261834
<button

0 commit comments

Comments
 (0)