Skip to content

Commit

Permalink
fix(checkbox): outline not visible when checked in high contrast mode (
Browse files Browse the repository at this point in the history
…#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)
  • Loading branch information
crisbeto authored and jelbourn committed Jan 27, 2020
1 parent 7a167a2 commit 75a7681
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
20 changes: 0 additions & 20 deletions src/material/checkbox/_checkbox-theme.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@import '../core/theming/theming';
@import '../core/typography/typography-utils';
@import '../../cdk/a11y/a11y';


@mixin mat-checkbox-theme($theme) {
Expand Down Expand Up @@ -34,12 +33,6 @@
// !important is needed here because a stroke must be set as an
// attribute on the SVG in order for line animation to work properly.
stroke: $checkbox-mark-color !important;

@include cdk-high-contrast(black-on-white) {
// Having the one above be !important ends up overriding the browser's automatic
// color inversion so we need to re-invert it ourselves for black-on-white.
stroke: #000 !important;
}
}

.mat-checkbox-mixedmark {
Expand Down Expand Up @@ -77,19 +70,6 @@
.mat-checkbox-label {
color: mat-color($foreground, secondary-text);
}

@include cdk-high-contrast {
opacity: 0.5;
}
}

// This one is moved down here so it can target both
// the theme colors and the disabled state.
@include cdk-high-contrast {
.mat-checkbox-background {
// Needs to be removed because it hides the checkbox outline.
background: none;
}
}

// Switch this to a solid color since we're using `opacity`
Expand Down
19 changes: 19 additions & 0 deletions src/material/checkbox/checkbox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,15 @@ $_mat-checkbox-mark-stroke-size: 2 / 15 * $mat-checkbox-size !default;
._mat-animation-noopable & {
transition: none;
}

// `.mat-checkbox` here is redundant, but we need it to increase the specificity so that
// these styles don't get overwritten by the `background-color` from the theme.
.mat-checkbox & {
@include cdk-high-contrast {
// Needs to be removed because it hides the checkbox outline.
background: none;
}
}
}

.mat-checkbox-persistent-ripple {
Expand Down Expand Up @@ -319,6 +328,12 @@ $_mat-checkbox-mark-stroke-size: 2 / 15 * $mat-checkbox-size !default;
dasharray: $_mat-checkbox-mark-path-length;
width: $_mat-checkbox-mark-stroke-size;
}

@include cdk-high-contrast(black-on-white) {
// In the checkbox theme this `stroke` has !important which ends up overriding the browser's
// automatic color inversion so we need to re-invert it ourselves for black-on-white.
stroke: #000 !important;
}
}

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

.mat-checkbox-disabled {
cursor: default;

@include cdk-high-contrast {
opacity: 0.5;
}
}

.mat-checkbox-anim {
Expand Down

0 comments on commit 75a7681

Please sign in to comment.