Skip to content

Commit 66fa26f

Browse files
crisbetommalerba
authored andcommitted
fix(dialog): not applying margins to new button variants (#11961)
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 02a3f3e commit 66fa26f

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/material/button/button.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,19 @@ export class MatButton extends _MatButtonMixinBase
9494
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode: string) {
9595
super(elementRef);
9696

97-
// For each of the variant selectors that is prevent in the button's host
97+
// For each of the variant selectors that is present in the button's host
9898
// attributes, add the correct corresponding class.
9999
for (const attr of BUTTON_HOST_ATTRIBUTES) {
100100
if (this._hasHostAttributes(attr)) {
101101
(this._getHostElement() as HTMLElement).classList.add(attr);
102102
}
103103
}
104104

105+
// Add a class that applies to all buttons. This makes it easier to target if somebody
106+
// wants to target all Material buttons. We do it here rather than `host` to ensure that
107+
// the class is applied to derived classes.
108+
elementRef.nativeElement.classList.add('mat-button-base');
109+
105110
this._focusMonitor.monitor(this._elementRef, true);
106111

107112
if (this.isRoundButton) {

src/material/dialog/dialog.scss

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

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

7067
[dir='rtl'] & {

0 commit comments

Comments
 (0)