Skip to content

Commit b3d1cee

Browse files
committed
fix(dialog): not applying margins to new button variants
A while ago we introduced a few new button variants, however we never updated the button selector in the dialog which means that they won't get the proper margin if they're placed next to each other. With the new variants, the dialog selector will grow exponentially since we have to list every possible button combination, which is why I added a new class to the button which makes it a lot easier to target any button.
1 parent aa09628 commit b3d1cee

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/lib/button/button.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class MatButton extends _MatButtonMixinBase
8888
/** Reference to the MatRipple instance of the button. */
8989
@ViewChild(MatRipple) ripple: MatRipple;
9090

91-
constructor(elementRef: ElementRef,
91+
constructor(elementRef: ElementRef<HTMLElement>,
9292
/**
9393
* @deprecated Platform checks for SSR are no longer needed
9494
* @deletion-target 7.0.0
@@ -100,14 +100,19 @@ export class MatButton extends _MatButtonMixinBase
100100
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode?: string) {
101101
super(elementRef);
102102

103-
// For each of the variant selectors that is prevent in the button's host
103+
// For each of the variant selectors that is present in the button's host
104104
// attributes, add the correct corresponding class.
105105
for (const attr of BUTTON_HOST_ATTRIBUTES) {
106106
if (this._hasHostAttributes(attr)) {
107-
(elementRef.nativeElement as HTMLElement).classList.add(attr);
107+
elementRef.nativeElement.classList.add(attr);
108108
}
109109
}
110110

111+
// Add a class that applies to all buttons. This makes it easier to target if somebody
112+
// wants to target all Material buttons. We do it here rather than `host` to ensure that
113+
// the class is applied to derived classes.
114+
elementRef.nativeElement.classList.add('mat-button-base');
115+
111116
this._focusMonitor.monitor(this._elementRef.nativeElement, true);
112117

113118
if (this.isRoundButton) {

src/lib/dialog/dialog.scss

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,7 @@ $mat-dialog-button-margin: 8px !default;
6262
justify-content: center;
6363
}
6464

65-
.mat-button + .mat-button,
66-
.mat-raised-button + .mat-raised-button,
67-
.mat-button + .mat-raised-button,
68-
.mat-raised-button + .mat-button {
65+
.mat-button-base + .mat-button-base {
6966
margin-left: $mat-dialog-button-margin;
7067

7168
[dir='rtl'] & {

0 commit comments

Comments
 (0)