Skip to content

Commit

Permalink
fix(material/list): checkmark not visible in high contrast mode (#29546)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
crisbeto committed Aug 7, 2024
1 parent 4718718 commit d22a24d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
16 changes: 16 additions & 0 deletions src/material/checkbox/_checkbox-common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@use '@angular/cdk';
@use '../core/tokens/m2/mdc/checkbox' as tokens-mdc-checkbox;
@use '../core/tokens/token-utils';
@use '../core/style/vendor-prefixes';

$_path-length: 29.7833385;
$_transition-duration: 90ms;
Expand Down Expand Up @@ -64,6 +65,10 @@ $_fallback-size: 40px;
.mdc-checkbox--disabled {
cursor: default;
pointer-events: none;

@include cdk.high-contrast(active, off) {
opacity: 0.5;
}
}

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

// Force browser to show background-color when using the print function
@include vendor-prefixes.color-adjust(exact);

@include token-utils.use-tokens($prefix, $slots) {
$layer-size: token-utils.get-token-variable(state-layer-size, $fallback: $_fallback-size);
$offset: calc((#{$layer-size} - #{$_icon-size}) / 2);
Expand Down Expand Up @@ -167,6 +175,10 @@ $_fallback-size: 40px;
// Always apply the color since the element becomes `opacity: 0`
// when unchecked. This makes the animation look better.
@include token-utils.create-token-slot(color, selected-checkmark-color);

@include cdk.high-contrast(active, off) {
color: CanvasText;
}
}
}

Expand All @@ -175,6 +187,10 @@ $_fallback-size: 40px;
&, &.mat-mdc-checkbox-disabled-interactive {
.mdc-checkbox__checkmark {
@include token-utils.create-token-slot(color, disabled-selected-checkmark-color);

@include cdk.high-contrast(active, off) {
color: CanvasText;
}
}
}
}
Expand Down
18 changes: 0 additions & 18 deletions src/material/checkbox/checkbox.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
@use '@angular/cdk';
@use '../core/style/layout-common';
@use '../core/style/vendor-prefixes';
@use '../core/tokens/m2/mat/checkbox' as tokens-mat-checkbox;
@use '../core/tokens/token-utils';
@use './checkbox-common';
Expand All @@ -17,11 +15,6 @@
// Disable the browser's tap highlight since we indicate state with the ripple instead.
-webkit-tap-highlight-color: transparent;

.mdc-checkbox__background {
// Force browser to show background-color when using the print function
@include vendor-prefixes.color-adjust(exact);
}

// Clicking the label toggles the checkbox, but MDC does not include any styles that inform the
// user of this. Therefore we add the pointer cursor on top of MDC's styles.
label {
Expand Down Expand Up @@ -69,17 +62,6 @@
display: none;
}

@include cdk.high-contrast(active, off) {
&.mat-mdc-checkbox-disabled {
opacity: 0.5;
}

.mdc-checkbox__checkmark {
--mdc-checkbox-selected-checkmark-color: CanvasText;
--mdc-checkbox-disabled-selected-checkmark-color: CanvasText;
}
}

// Apply base styles to the MDC ripple when not hovered, focused, or pressed.
.mdc-checkbox__ripple {
opacity: 0;
Expand Down

0 comments on commit d22a24d

Please sign in to comment.