Skip to content

Commit

Permalink
fix(material-experimental/mdc-snack-bar): use MDC-based button
Browse files Browse the repository at this point in the history
Switches the MDC-based snack bar to use the MDC-based button. In general we should
be using the MDC versions of components together, when possible.
  • Loading branch information
crisbeto committed Dec 26, 2020
1 parent 71b7b15 commit b0adc58
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/material-experimental/mdc-snack-bar/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ng_module(
module_name = "@angular/material-experimental/mdc-snack-bar",
deps = [
"//src:dev_mode_types",
"//src/material-experimental/mdc-button",
"//src/material-experimental/mdc-core",
"//src/material/snack-bar",
"@npm//@angular/core",
Expand Down Expand Up @@ -76,7 +77,10 @@ ng_test_library(

ng_web_test_suite(
name = "unit_tests",
static_files = ["@npm//:node_modules/@material/snackbar/dist/mdc.snackbar.js"],
static_files = [
"@npm//:node_modules/@material/snackbar/dist/mdc.snackbar.js",
"@npm//:node_modules/@material/ripple/dist/mdc.ripple.js",
],
deps = [
":unit_test_sources",
"//src/material-experimental:mdc_require_config.js",
Expand Down
6 changes: 6 additions & 0 deletions src/material-experimental/mdc-snack-bar/_snack-bar-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
@include mdc-snackbar-core-styles($query: $mat-theme-styles-query);
}

// Usually this color is provided by the `mdc-snackbar-core-styles` mixin, but our styles
// to handle unthemed buttons have a higher specificity so we have to re-provide it here.
.mat-mdc-snack-bar-container .mat-mdc-snack-bar-action.mdc-snackbar__action {
color: $mdc-snackbar-action-ink-color;
}

$mdc-snackbar-fill-color: $orig-mdc-snackbar-fill-color !global;
$mdc-snackbar-label-ink-color: $orig-mdc-snackbar-label-ink-color !global;
$mdc-snackbar-dismiss-ink-color: $orig-mdc-snackbar-dismiss-ink-color !global;
Expand Down
2 changes: 1 addition & 1 deletion src/material-experimental/mdc-snack-bar/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {OverlayModule} from '@angular/cdk/overlay';
import {PortalModule} from '@angular/cdk/portal';
import {CommonModule} from '@angular/common';
import {NgModule} from '@angular/core';
import {MatButtonModule} from '@angular/material/button';
import {MatButtonModule} from '@angular/material-experimental/mdc-button';
import {MatCommonModule} from '@angular/material-experimental/mdc-core';

import {MatSimpleSnackBar} from './simple-snack-bar';
Expand Down
6 changes: 3 additions & 3 deletions src/material-experimental/mdc-snack-bar/snack-bar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ describe('MatSnackBar', () => {
expect(messageElement.textContent)
.toContain(simpleMessage, `Expected the snack bar message to be '${simpleMessage}'`);

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

Expand Down Expand Up @@ -363,7 +363,7 @@ describe('MatSnackBar', () => {
snackBarRef.onAction().subscribe({complete: actionCompleteSpy});

let actionButton =
overlayContainerElement.querySelector('button.mat-button') as HTMLButtonElement;
overlayContainerElement.querySelector('button.mat-mdc-button') as HTMLButtonElement;
actionButton.click();
viewContainerFixture.detectChanges();
flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ ng_web_test_suite(
name = "unit_tests",
static_files = [
"@npm//:node_modules/@material/snackbar/dist/mdc.snackbar.js",
"@npm//:node_modules/@material/ripple/dist/mdc.ripple.js",
],
deps = [
":unit_tests_lib",
Expand Down

0 comments on commit b0adc58

Please sign in to comment.