Skip to content

Commit

Permalink
fix(material-experimental/mdc-snack-bar): use MDC-based button (#21442)
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.

Fixes #22024
  • Loading branch information
crisbeto committed Mar 5, 2021
1 parent d869d79 commit 9f879b2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 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 @@ -77,7 +78,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
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@
$mdc-snackbar-label-ink-color: $orig-mdc-snackbar-label-ink-color !global;
$mdc-snackbar-dismiss-ink-color: $orig-mdc-snackbar-dismiss-ink-color !global;

.mat-mdc-simple-snack-bar .mdc-snackbar__action {
// The extra level of nesting here is to increase the specificity.
.mat-mdc-simple-snack-bar .mat-mdc-snack-bar-actions .mdc-snackbar__action {
$is-dark-theme: map.get($config, is-dark);
$accent: map.get($config, accent);
color: if($is-dark-theme, inherit, theming.color($accent, text));

.mat-ripple-element {
background-color: currentColor;
opacity: 0.1;
}
}
}

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 @@ -226,7 +226,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 @@ -249,7 +249,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 @@ -388,7 +388,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 9f879b2

Please sign in to comment.