Skip to content

Commit 6220b72

Browse files
crisbetoandrewseguin
authored andcommitted
fix(checkbox): high contrast accessibility improvements (#11633)
* Fixes the checkbox outline becoming hidden when it's selected. * Fixes the checkmark and mixedmark not being visible with white-on-black settings. * Fixes the disabled state not being visible. * Adds a parameter to the `cdk-high-contrast` mixin that allows for targeting a specific high contrast setting. Relates to #11623.
1 parent 703da89 commit 6220b72

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

src/cdk/a11y/_a11y.scss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222
* Applies styles for users in high contrast mode. Note that this only applies
2323
* to Microsoft browsers. Chrome can be included by checking for the `html[hc]`
2424
* attribute, however Chrome handles high contrast differently.
25+
* @param target Which kind of high contrast setting to target. Defaults to `active`, can be
26+
* `white-on-black` or `black-on-white`.
2527
*/
26-
@mixin cdk-high-contrast {
27-
@media screen and (-ms-high-contrast: active) {
28+
@mixin cdk-high-contrast($target: active) {
29+
@media screen and (-ms-high-contrast: $target) {
2830
@content;
2931
}
3032
}

src/lib/checkbox/_checkbox-theme.scss

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

45

56
@mixin mat-checkbox-theme($theme) {
@@ -29,9 +30,15 @@
2930
}
3031

3132
.mat-checkbox-checkmark-path {
32-
// !important is needed here because a stroke must be set as an attribute on the SVG in order
33-
// for line animation to work properly.
33+
// !important is needed here because a stroke must be set as an
34+
// attribute on the SVG in order for line animation to work properly.
3435
stroke: $checkbox-mark-color !important;
36+
37+
@include cdk-high-contrast(black-on-white) {
38+
// Having the one above be !important ends up overriding the browser's automatic
39+
// color inversion so we need to re-invert it ourselves for black-on-white.
40+
stroke: #000 !important;
41+
}
3542
}
3643

3744
.mat-checkbox-mixedmark {
@@ -68,6 +75,19 @@
6875
.mat-checkbox-label {
6976
color: $disabled-color;
7077
}
78+
79+
@include cdk-high-contrast {
80+
opacity: 0.5;
81+
}
82+
}
83+
84+
// This one is moved down here so it can target both
85+
// the theme colors and the disabled state.
86+
@include cdk-high-contrast {
87+
.mat-checkbox-background {
88+
// Needs to be removed because it hides the checkbox outline.
89+
background: none;
90+
}
7191
}
7292

7393
.mat-checkbox:not(.mat-checkbox-disabled) {

src/lib/checkbox/checkbox.scss

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
@import '../core/ripple/ripple';
55
@import '../core/style/layout-common';
66
@import '../core/style/noop-animation';
7+
@import '../../cdk/a11y/a11y';
78

89
// Manual calculation done on SVG
910
$_mat-checkbox-mark-path-length: 22.910259;
@@ -275,11 +276,18 @@ $_mat-checkbox-mark-stroke-size: 2 / 15 * $mat-checkbox-size !default;
275276
}
276277

277278
.mat-checkbox-mixedmark {
278-
@extend %mat-checkbox-mark;
279+
$height: floor($_mat-checkbox-mark-stroke-size);
279280

280-
height: floor($_mat-checkbox-mark-stroke-size);
281+
@extend %mat-checkbox-mark;
282+
height: $height;
281283
opacity: 0;
282284
transform: scaleX(0) rotate(0deg);
285+
286+
@include cdk-high-contrast {
287+
height: 0;
288+
border-top: solid $height;
289+
margin-top: $height;
290+
}
283291
}
284292

285293
.mat-checkbox-label-before {

0 commit comments

Comments
 (0)