Skip to content

fix(snack-bar): use mat-button like styling in simple snack bar #7506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib/snack-bar/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ng_module(
"simple_snack_bar_css",
],
deps = [
"//src/lib/button",
"//src/lib/core",
"//src/cdk/a11y",
"//src/cdk/layout",
Expand Down
7 changes: 3 additions & 4 deletions src/lib/snack-bar/simple-snack-bar.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{{data.message}}

<button
class="mat-simple-snackbar-action"
*ngIf="hasAction"
(click)="action()">{{data.action}}</button>
<div class="mat-simple-snackbar-action" *ngIf="hasAction">
<button mat-button (click)="action()">{{data.action}}</button>
</div>
26 changes: 19 additions & 7 deletions src/lib/snack-bar/simple-snack-bar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,36 @@
@import '../core/style/button-common';
@import '../core/style/list-common';

$mat-snack-bar-button-margin: 48px !default;
$mat-snack-bar-button-horizontal-margin: 8px !default;
$mat-snack-bar-button-height: 36px !default;
$mat-snack-bar-line-height: 20px !default;
// Button vertical margin is used to ensure that a button height of 36px, when the containing
// space falls below 36px.
$mat-snack-bar-button-vertical-margin:
-(($mat-snack-bar-button-height - $mat-snack-bar-line-height) / 2);

.mat-simple-snackbar {
display: flex;
justify-content: space-between;
line-height: 20px;
line-height: $mat-snack-bar-line-height;
opacity: 1;
}

.mat-simple-snackbar-action {
@include mat-button-reset;

background: none;
display: flex;
flex-direction: column;
flex-shrink: 0;
margin-left: $mat-snack-bar-button-margin;
justify-content: space-around;
margin: $mat-snack-bar-button-vertical-margin 0
$mat-snack-bar-button-vertical-margin $mat-snack-bar-button-horizontal-margin;

button {
flex: 1;
max-height: $mat-snack-bar-button-height;
}

[dir='rtl'] & {
margin-right: $mat-snack-bar-button-margin;
margin-left: 0;
margin-right: $mat-snack-bar-button-horizontal-margin;
}
}
2 changes: 2 additions & 0 deletions src/lib/snack-bar/snack-bar-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {PortalModule} from '@angular/cdk/portal';
import {CommonModule} from '@angular/common';
import {NgModule} from '@angular/core';
import {MatCommonModule} from '@angular/material/core';
import {MatButtonModule} from '@angular/material/button';
import {SimpleSnackBar} from './simple-snack-bar';
import {MatSnackBar} from './snack-bar';
import {MatSnackBarContainer} from './snack-bar-container';
Expand All @@ -21,6 +22,7 @@ import {MatSnackBarContainer} from './snack-bar-container';
OverlayModule,
PortalModule,
CommonModule,
MatButtonModule,
MatCommonModule,
],
exports: [MatSnackBarContainer, MatCommonModule],
Expand Down
8 changes: 4 additions & 4 deletions src/lib/snack-bar/snack-bar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('MatSnackBar', () => {
expect(messageElement.textContent)
.toContain(simpleMessage, `Expected the snack bar message to be '${simpleMessage}'`);

let buttonElement = overlayContainerElement.querySelector('button.mat-simple-snackbar-action')!;
let buttonElement = overlayContainerElement.querySelector('button.mat-button')!;
expect(buttonElement.tagName)
.toBe('BUTTON', 'Expected snack bar action label to be a <button>');
expect(buttonElement.textContent)
Expand All @@ -129,7 +129,7 @@ describe('MatSnackBar', () => {
let messageElement = overlayContainerElement.querySelector('snack-bar-container')!;
expect(messageElement.textContent)
.toContain(simpleMessage, `Expected the snack bar message to be '${simpleMessage}'`);
expect(overlayContainerElement.querySelector('button.mat-simple-snackbar-action'))
expect(overlayContainerElement.querySelector('button.mat-button'))
.toBeNull('Expected the query selection for action label to be null');
});

Expand Down Expand Up @@ -285,8 +285,8 @@ describe('MatSnackBar', () => {
snackBarRef.afterDismissed().subscribe(undefined, undefined, dismissCompleteSpy);
snackBarRef.onAction().subscribe(undefined, undefined, actionCompleteSpy);

const actionButton =
overlayContainerElement.querySelector('.mat-simple-snackbar-action') as HTMLButtonElement;
let actionButton =
overlayContainerElement.querySelector('button.mat-button') as HTMLButtonElement;
actionButton.click();
viewContainerFixture.detectChanges();
tick();
Expand Down