Skip to content

Commit 9f879b2

Browse files
authored
fix(material-experimental/mdc-snack-bar): use MDC-based button (#21442)
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
1 parent d869d79 commit 9f879b2

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

src/material-experimental/mdc-snack-bar/BUILD.bazel

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ ng_module(
2222
module_name = "@angular/material-experimental/mdc-snack-bar",
2323
deps = [
2424
"//src:dev_mode_types",
25+
"//src/material-experimental/mdc-button",
2526
"//src/material-experimental/mdc-core",
2627
"//src/material/snack-bar",
2728
"@npm//@angular/core",
@@ -77,7 +78,10 @@ ng_test_library(
7778

7879
ng_web_test_suite(
7980
name = "unit_tests",
80-
static_files = ["@npm//:node_modules/@material/snackbar/dist/mdc.snackbar.js"],
81+
static_files = [
82+
"@npm//:node_modules/@material/snackbar/dist/mdc.snackbar.js",
83+
"@npm//:node_modules/@material/ripple/dist/mdc.ripple.js",
84+
],
8185
deps = [
8286
":unit_test_sources",
8387
"//src/material-experimental:mdc_require_config.js",

src/material-experimental/mdc-snack-bar/_snack-bar-theme.scss

+7-1
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,16 @@
3636
$mdc-snackbar-label-ink-color: $orig-mdc-snackbar-label-ink-color !global;
3737
$mdc-snackbar-dismiss-ink-color: $orig-mdc-snackbar-dismiss-ink-color !global;
3838

39-
.mat-mdc-simple-snack-bar .mdc-snackbar__action {
39+
// The extra level of nesting here is to increase the specificity.
40+
.mat-mdc-simple-snack-bar .mat-mdc-snack-bar-actions .mdc-snackbar__action {
4041
$is-dark-theme: map.get($config, is-dark);
4142
$accent: map.get($config, accent);
4243
color: if($is-dark-theme, inherit, theming.color($accent, text));
44+
45+
.mat-ripple-element {
46+
background-color: currentColor;
47+
opacity: 0.1;
48+
}
4349
}
4450
}
4551

src/material-experimental/mdc-snack-bar/module.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {OverlayModule} from '@angular/cdk/overlay';
1010
import {PortalModule} from '@angular/cdk/portal';
1111
import {CommonModule} from '@angular/common';
1212
import {NgModule} from '@angular/core';
13-
import {MatButtonModule} from '@angular/material/button';
13+
import {MatButtonModule} from '@angular/material-experimental/mdc-button';
1414
import {MatCommonModule} from '@angular/material-experimental/mdc-core';
1515

1616
import {MatSimpleSnackBar} from './simple-snack-bar';

src/material-experimental/mdc-snack-bar/snack-bar.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ describe('MatSnackBar', () => {
226226
expect(messageElement.textContent)
227227
.toContain(simpleMessage, `Expected the snack bar message to be '${simpleMessage}'`);
228228

229-
let buttonElement = overlayContainerElement.querySelector('button.mat-button')!;
229+
let buttonElement = overlayContainerElement.querySelector('button.mat-mdc-button')!;
230230
expect(buttonElement.tagName)
231231
.toBe('BUTTON', 'Expected snack bar action label to be a <button>');
232232
expect((buttonElement.textContent || '').trim())
@@ -249,7 +249,7 @@ describe('MatSnackBar', () => {
249249
let messageElement = overlayContainerElement.querySelector('mat-mdc-snack-bar-container')!;
250250
expect(messageElement.textContent)
251251
.toContain(simpleMessage, `Expected the snack bar message to be '${simpleMessage}'`);
252-
expect(overlayContainerElement.querySelector('button.mat-button'))
252+
expect(overlayContainerElement.querySelector('button.mat-mdc-button'))
253253
.toBeNull('Expected the query selection for action label to be null');
254254
});
255255

@@ -388,7 +388,7 @@ describe('MatSnackBar', () => {
388388
snackBarRef.onAction().subscribe({complete: actionCompleteSpy});
389389

390390
let actionButton =
391-
overlayContainerElement.querySelector('button.mat-button') as HTMLButtonElement;
391+
overlayContainerElement.querySelector('button.mat-mdc-button') as HTMLButtonElement;
392392
actionButton.click();
393393
viewContainerFixture.detectChanges();
394394
flush();

src/material-experimental/mdc-snack-bar/testing/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ ng_web_test_suite(
3434
name = "unit_tests",
3535
static_files = [
3636
"@npm//:node_modules/@material/snackbar/dist/mdc.snackbar.js",
37+
"@npm//:node_modules/@material/ripple/dist/mdc.ripple.js",
3738
],
3839
deps = [
3940
":unit_tests_lib",

0 commit comments

Comments
 (0)