Skip to content

Commit 75a7681

Browse files
crisbetojelbourn
authored andcommitted
fix(checkbox): outline not visible when checked in high contrast mode (#18048)
Fixes checked checkboxes blending in with the background in high contrast mode. This is something that used to work, but might've regressed after we made `cdk-high-contrast` to generate a class selector which has a different specificity. Also moves the checkbox high contrast styles into the main component styles so they don't have to be repeated for each theme. (cherry picked from commit d9cf175)
1 parent 7a167a2 commit 75a7681

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

src/material/checkbox/_checkbox-theme.scss

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
@import '../core/theming/theming';
22
@import '../core/typography/typography-utils';
3-
@import '../../cdk/a11y/a11y';
43

54

65
@mixin mat-checkbox-theme($theme) {
@@ -34,12 +33,6 @@
3433
// !important is needed here because a stroke must be set as an
3534
// attribute on the SVG in order for line animation to work properly.
3635
stroke: $checkbox-mark-color !important;
37-
38-
@include cdk-high-contrast(black-on-white) {
39-
// Having the one above be !important ends up overriding the browser's automatic
40-
// color inversion so we need to re-invert it ourselves for black-on-white.
41-
stroke: #000 !important;
42-
}
4336
}
4437

4538
.mat-checkbox-mixedmark {
@@ -77,19 +70,6 @@
7770
.mat-checkbox-label {
7871
color: mat-color($foreground, secondary-text);
7972
}
80-
81-
@include cdk-high-contrast {
82-
opacity: 0.5;
83-
}
84-
}
85-
86-
// This one is moved down here so it can target both
87-
// the theme colors and the disabled state.
88-
@include cdk-high-contrast {
89-
.mat-checkbox-background {
90-
// Needs to be removed because it hides the checkbox outline.
91-
background: none;
92-
}
9373
}
9474

9575
// Switch this to a solid color since we're using `opacity`

src/material/checkbox/checkbox.scss

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,15 @@ $_mat-checkbox-mark-stroke-size: 2 / 15 * $mat-checkbox-size !default;
275275
._mat-animation-noopable & {
276276
transition: none;
277277
}
278+
279+
// `.mat-checkbox` here is redundant, but we need it to increase the specificity so that
280+
// these styles don't get overwritten by the `background-color` from the theme.
281+
.mat-checkbox & {
282+
@include cdk-high-contrast {
283+
// Needs to be removed because it hides the checkbox outline.
284+
background: none;
285+
}
286+
}
278287
}
279288

280289
.mat-checkbox-persistent-ripple {
@@ -319,6 +328,12 @@ $_mat-checkbox-mark-stroke-size: 2 / 15 * $mat-checkbox-size !default;
319328
dasharray: $_mat-checkbox-mark-path-length;
320329
width: $_mat-checkbox-mark-stroke-size;
321330
}
331+
332+
@include cdk-high-contrast(black-on-white) {
333+
// In the checkbox theme this `stroke` has !important which ends up overriding the browser's
334+
// automatic color inversion so we need to re-invert it ourselves for black-on-white.
335+
stroke: #000 !important;
336+
}
322337
}
323338

324339
.mat-checkbox-mixedmark {
@@ -393,6 +408,10 @@ $_mat-checkbox-mark-stroke-size: 2 / 15 * $mat-checkbox-size !default;
393408

394409
.mat-checkbox-disabled {
395410
cursor: default;
411+
412+
@include cdk-high-contrast {
413+
opacity: 0.5;
414+
}
396415
}
397416

398417
.mat-checkbox-anim {

0 commit comments

Comments
 (0)