Skip to content

Commit aafdf0f

Browse files
committed
9.2. Address CI failures and reviewer feedback
Fixes unit tests in Edge and approves the new API goldens for checkbox.
1 parent 30a61a5 commit aafdf0f

File tree

10 files changed

+186
-65
lines changed

10 files changed

+186
-65
lines changed

src/lib/checkbox/checkbox-module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {MatCommonModule, MatRippleModule} from '@angular/material/core';
1313
import {MatCheckbox} from './checkbox';
1414
import {MatCheckboxRequiredValidator} from './checkbox-required-validator';
1515

16+
/** This module is used by both original and MDC-based checkbox implementations. */
1617
@NgModule({
1718
exports: [MatCheckboxRequiredValidator],
1819
declarations: [MatCheckboxRequiredValidator],

src/material-experimental/mdc-checkbox/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ component by following these steps:
1414
```
1515

1616
2. In your `angular.json`, make sure `node_modules/` is listed as a Sass include path. This is
17-
needed for the Sass compiler to be able to find the MDC Web Sass files.
17+
needed for the Sass compiler to be able to find the MDC Web Sass files.
1818

1919
```json
2020
...
@@ -74,7 +74,7 @@ differences:
7474
* The experimental `MatCheckbox` does not have a public `ripple` property.
7575

7676
## Replacing the standard checkbox in an existing app
77-
Because the experimental API mirrors the API for the standard checkbox, it cn easily be swapped in
77+
Because the experimental API mirrors the API for the standard checkbox, it can easily be swapped in
7878
by just changing the import paths. There is currently no schematic for this, but you can run the
7979
following string replace across your TypeScript files:
8080

src/material-experimental/mdc-checkbox/_mdc-checkbox.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
$accent: mat-color(map-get($theme, accent));
1111
$warn: mat-color(map-get($theme, warn));
1212

13-
// Save original values of MDC global variables.
13+
// Save original values of MDC global variables. We need to save these so we can restore the
14+
// variables to their original values and prevent unintended side effects from using this mixin.
1415
$orig-mdc-checkbox-mark-color: $mdc-checkbox-mark-color;
1516
$orig-mdc-checkbox-baseline-theme-color: $mdc-checkbox-baseline-theme-color;
1617
$orig-mdc-checkbox-border-color: $mdc-checkbox-border-color;
@@ -25,6 +26,9 @@
2526
@include mdc-checkbox-without-ripple($query: $mat-theme-styles-query);
2627
@include mdc-form-field-core-styles($query: $mat-theme-styles-query);
2728

29+
// MDC's checkbox doesn't support a `color` property. We add support for it by adding a CSS
30+
// class for accent and warn style, and applying the appropriate overrides below. Since we don't
31+
// use MDC's ripple, we also need to set the color for our replacement ripple.
2832
.mat-mdc-checkbox {
2933
.mat-ripple-element {
3034
background: $primary;

src/material-experimental/mdc-checkbox/checkbox.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
[required]="required"
1919
[tabIndex]="tabIndex"
2020
(blur)="_onBlur()"
21-
(change)="_onChange($event)"/>
21+
(click)="_onClick()"
22+
(change)="$event.stopPropagation()"/>
2223
<div class="mdc-checkbox__background">
2324
<svg class="mdc-checkbox__checkmark"
2425
focusable="false"

src/material-experimental/mdc-checkbox/checkbox.scss

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,31 @@
88
@include mdc-form-field-core-styles($query: $mat-base-styles-query);
99

1010
.mat-mdc-checkbox {
11-
// stylelint-disable selector-class-pattern
12-
11+
// The MDC checkbox styles related to the hover state are intertwined with the MDC ripple styles.
12+
// We currently don't use the MDC ripple due to size concerns, therefore we need to add some
13+
// additional styles to restore the hover state.
1314
.mdc-checkbox:hover
1415
.mdc-checkbox__native-control:not([disabled]) ~ .mdc-checkbox__background::before {
1516
opacity: map-get($mdc-ripple-dark-ink-opacities, hover);
1617
transform: scale(2.75, 2.75);
17-
transition: mdc-checkbox-transition-enter(opacity, 0ms, 80ms),
18-
mdc-checkbox-transition-enter(transform, 0ms, 80ms);
18+
transition: mdc-checkbox-transition-enter(opacity, 0, 80ms),
19+
mdc-checkbox-transition-enter(transform, 0, 80ms);
1920
}
2021

2122
.mdc-checkbox:hover .mdc-checkbox__native-control:focus ~ .mdc-checkbox__background::before {
2223
opacity: map-get($mdc-ripple-dark-ink-opacities, hover) +
2324
map-get($mdc-ripple-dark-ink-opacities, focus);
2425
}
2526

27+
// We use an Angular Material ripple rather than an MDC ripple due to size concerns, so we need to
28+
// style it appropriately.
2629
.mat-ripple-element {
2730
opacity: map-get($mdc-ripple-dark-ink-opacities, press);
2831
}
2932

33+
// Angular Material supports disabling all animations when NoopAnimationsModule is imported.
34+
// TODO(mmalerba): Look into using MDC's Sass queries to separate the animation styles and
35+
// conditionally add them. Consider the size cost when deciding whether to switch.
3036
&._mat-animation-noopable {
3137
*,
3238
*::before {
@@ -35,8 +41,9 @@
3541
}
3642
}
3743

44+
// The MDC styles result in extra padding if the label is present but empty. To fix this we hide
45+
// the label when it is empty.
3846
label:empty {
3947
display: none;
4048
}
41-
// stylelint-enable selector-class-pattern
4249
}

0 commit comments

Comments
 (0)