Skip to content

Commit d22a24d

Browse files
authored
fix(material/list): checkmark not visible in high contrast mode (#29546)
We had a patch to show the checkmark in high contrast mode, but it was only applied to `mat-checkbox`. These changes move it to the common styles so it also shows up for `mat-list-option`.
1 parent 4718718 commit d22a24d

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

src/material/checkbox/_checkbox-common.scss

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
@use '@angular/cdk';
33
@use '../core/tokens/m2/mdc/checkbox' as tokens-mdc-checkbox;
44
@use '../core/tokens/token-utils';
5+
@use '../core/style/vendor-prefixes';
56

67
$_path-length: 29.7833385;
78
$_transition-duration: 90ms;
@@ -64,6 +65,10 @@ $_fallback-size: 40px;
6465
.mdc-checkbox--disabled {
6566
cursor: default;
6667
pointer-events: none;
68+
69+
@include cdk.high-contrast(active, off) {
70+
opacity: 0.5;
71+
}
6772
}
6873

6974
.mdc-checkbox__background {
@@ -82,6 +87,9 @@ $_fallback-size: 40px;
8287
transition: background-color $_transition-duration $_exit-curve,
8388
border-color $_transition-duration $_exit-curve;
8489

90+
// Force browser to show background-color when using the print function
91+
@include vendor-prefixes.color-adjust(exact);
92+
8593
@include token-utils.use-tokens($prefix, $slots) {
8694
$layer-size: token-utils.get-token-variable(state-layer-size, $fallback: $_fallback-size);
8795
$offset: calc((#{$layer-size} - #{$_icon-size}) / 2);
@@ -167,6 +175,10 @@ $_fallback-size: 40px;
167175
// Always apply the color since the element becomes `opacity: 0`
168176
// when unchecked. This makes the animation look better.
169177
@include token-utils.create-token-slot(color, selected-checkmark-color);
178+
179+
@include cdk.high-contrast(active, off) {
180+
color: CanvasText;
181+
}
170182
}
171183
}
172184

@@ -175,6 +187,10 @@ $_fallback-size: 40px;
175187
&, &.mat-mdc-checkbox-disabled-interactive {
176188
.mdc-checkbox__checkmark {
177189
@include token-utils.create-token-slot(color, disabled-selected-checkmark-color);
190+
191+
@include cdk.high-contrast(active, off) {
192+
color: CanvasText;
193+
}
178194
}
179195
}
180196
}

src/material/checkbox/checkbox.scss

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
@use '@angular/cdk';
21
@use '../core/style/layout-common';
3-
@use '../core/style/vendor-prefixes';
42
@use '../core/tokens/m2/mat/checkbox' as tokens-mat-checkbox;
53
@use '../core/tokens/token-utils';
64
@use './checkbox-common';
@@ -17,11 +15,6 @@
1715
// Disable the browser's tap highlight since we indicate state with the ripple instead.
1816
-webkit-tap-highlight-color: transparent;
1917

20-
.mdc-checkbox__background {
21-
// Force browser to show background-color when using the print function
22-
@include vendor-prefixes.color-adjust(exact);
23-
}
24-
2518
// Clicking the label toggles the checkbox, but MDC does not include any styles that inform the
2619
// user of this. Therefore we add the pointer cursor on top of MDC's styles.
2720
label {
@@ -69,17 +62,6 @@
6962
display: none;
7063
}
7164

72-
@include cdk.high-contrast(active, off) {
73-
&.mat-mdc-checkbox-disabled {
74-
opacity: 0.5;
75-
}
76-
77-
.mdc-checkbox__checkmark {
78-
--mdc-checkbox-selected-checkmark-color: CanvasText;
79-
--mdc-checkbox-disabled-selected-checkmark-color: CanvasText;
80-
}
81-
}
82-
8365
// Apply base styles to the MDC ripple when not hovered, focused, or pressed.
8466
.mdc-checkbox__ripple {
8567
opacity: 0;

0 commit comments

Comments
 (0)