Skip to content

Commit e18ab5d

Browse files
crisbetotinayuangao
authored andcommitted
feat(dialog): add the ability to align the content of md-dialog-actions (#2557)
* feat(dialog): add the ability to align the content of md-dialog-actions Adds the `align` attribute, which can be set to `end` or `middle`, that allows users to align the content of the `md-dialog-actions`. Fixes #2483. * Fix linter error. * Rename "middle" to "center".
1 parent 52ade97 commit e18ab5d

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

src/demo-app/dialog/dialog-demo.html

+8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ <h2>Dialog position</h2>
2626

2727
<h2>Other options</h2>
2828

29+
<p>
30+
<md-select placeholder="Button alignment" [(ngModel)]="actionsAlignment">
31+
<md-option>Start</md-option>
32+
<md-option value="end">End</md-option>
33+
<md-option value="center">Center</md-option>
34+
</md-select>
35+
</p>
36+
2937
<md-checkbox [(ngModel)]="config.disableClose">Disable close</md-checkbox>
3038
</md-card-content>
3139
</md-card>

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {MdDialog, MdDialogRef, MdDialogConfig} from '@angular/material';
1010
export class DialogDemo {
1111
dialogRef: MdDialogRef<JazzDialog>;
1212
lastCloseResult: string;
13+
actionsAlignment: string;
1314
config: MdDialogConfig = {
1415
disableClose: false,
1516
width: '',
@@ -34,7 +35,8 @@ export class DialogDemo {
3435
}
3536

3637
openContentElement() {
37-
this.dialog.open(ContentElementDialog, this.config);
38+
let dialogRef = this.dialog.open(ContentElementDialog, this.config);
39+
dialogRef.componentInstance.actionsAlignment = this.actionsAlignment;
3840
}
3941
}
4042

@@ -78,7 +80,7 @@ export class JazzDialog {
7880
</p>
7981
</md-dialog-content>
8082
81-
<md-dialog-actions>
83+
<md-dialog-actions [attr.align]="actionsAlignment">
8284
<button
8385
md-raised-button
8486
color="primary"
@@ -92,4 +94,6 @@ export class JazzDialog {
9294
</md-dialog-actions>
9395
`
9496
})
95-
export class ContentElementDialog { }
97+
export class ContentElementDialog {
98+
actionsAlignment: string;
99+
}

src/lib/dialog/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ A reference to the dialog created by the MdDialog `open` method.
3737
| `md-dialog-title` | Marks the title of the dialog.
3838
| `md-dialog-content` | Scrollable content of the dialog.
3939
| `md-dialog-close` | When added to a `button`, makes the element act as a close button for the dialog.
40-
| `md-dialog-actions` | Wrapper for the set of actions at the bottom of a dialog. Typically contains buttons.
40+
| `md-dialog-actions` | Wrapper for the set of actions at the bottom of a dialog. Typically contains buttons. The element's content can be aligned via the `align` attribute either to the `center` or the `end`. |
4141

4242
## Example
4343
The service can be injected in a component.

src/lib/dialog/dialog.scss

+9-1
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,20 @@ md-dialog-content, [md-dialog-content], mat-dialog-content, [mat-dialog-content]
4343

4444
md-dialog-actions, [md-dialog-actions], mat-dialog-actions, [mat-dialog-actions] {
4545
padding: $md-dialog-padding / 2 0;
46-
display: block;
46+
display: flex;
4747

4848
&:last-child {
4949
// If the actions are the last element in a dialog, we need to pull them down
5050
// over the dialog padding, in order to avoid the action's padding stacking
5151
// with the dialog's.
5252
margin-bottom: -$md-dialog-padding;
5353
}
54+
55+
&[align='end'] {
56+
justify-content: flex-end;
57+
}
58+
59+
&[align='center'] {
60+
justify-content: center;
61+
}
5462
}

0 commit comments

Comments
 (0)