Skip to content

Commit

Permalink
fix(dialog): not applying margins to new button variants (#11961)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
crisbeto authored and mmalerba committed Aug 15, 2019
1 parent 02a3f3e commit 66fa26f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/material/button/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,19 @@ export class MatButton extends _MatButtonMixinBase
@Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode: string) {
super(elementRef);

// For each of the variant selectors that is prevent in the button's host
// For each of the variant selectors that is present in the button's host
// attributes, add the correct corresponding class.
for (const attr of BUTTON_HOST_ATTRIBUTES) {
if (this._hasHostAttributes(attr)) {
(this._getHostElement() as HTMLElement).classList.add(attr);
}
}

// Add a class that applies to all buttons. This makes it easier to target if somebody
// wants to target all Material buttons. We do it here rather than `host` to ensure that
// the class is applied to derived classes.
elementRef.nativeElement.classList.add('mat-button-base');

this._focusMonitor.monitor(this._elementRef, true);

if (this.isRoundButton) {
Expand Down
5 changes: 1 addition & 4 deletions src/material/dialog/dialog.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ $mat-dialog-button-margin: 8px !default;
justify-content: center;
}

.mat-button + .mat-button,
.mat-raised-button + .mat-raised-button,
.mat-button + .mat-raised-button,
.mat-raised-button + .mat-button {
.mat-button-base + .mat-button-base {
margin-left: $mat-dialog-button-margin;

[dir='rtl'] & {
Expand Down

0 comments on commit 66fa26f

Please sign in to comment.