Skip to content

Commit dd2f465

Browse files
crisbetojosephperrott
authored andcommitted
fix(button-toggle): not usable in high contrast mode (#11097)
1 parent 645edc5 commit dd2f465

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/lib/button-toggle/button-toggle.scss

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@import '../core/style/elevation';
22
@import '../core/style/vendor-prefixes';
33
@import '../core/style/layout-common';
4+
@import '../../cdk/a11y/a11y';
45

56
$mat-button-toggle-padding: 0 16px !default;
67
$mat-button-toggle-height: 36px !default;
@@ -18,6 +19,10 @@ $mat-button-toggle-border-radius: 2px !default;
1819
cursor: pointer;
1920
white-space: nowrap;
2021
overflow: hidden;
22+
23+
@include cdk-high-contrast {
24+
outline: solid 1px;
25+
}
2126
}
2227

2328
.mat-button-toggle-vertical {
@@ -45,6 +50,11 @@ $mat-button-toggle-border-radius: 2px !default;
4550
&.cdk-keyboard-focused {
4651
.mat-button-toggle-focus-overlay {
4752
opacity: 1;
53+
54+
// In high contrast mode `opacity: 1` will show the overlay as solid so we fall back 0.5.
55+
@include cdk-high-contrast {
56+
opacity: 0.5;
57+
}
4858
}
4959
}
5060
}
@@ -69,6 +79,17 @@ $mat-button-toggle-border-radius: 2px !default;
6979
pointer-events: none;
7080
opacity: 0;
7181
@include mat-fill;
82+
83+
.mat-button-toggle-checked & {
84+
// Changing the background color for the selected item won't be visible in high contrast mode.
85+
// We fall back to using the overlay to draw a brighter, semi-transparent tint on top instead.
86+
// It uses a border, because the browser will render it using a brighter color.
87+
@include cdk-high-contrast {
88+
opacity: 0.5;
89+
height: 0;
90+
border-bottom: solid $mat-button-toggle-height;
91+
}
92+
}
7293
}
7394

7495
.mat-button-toggle-ripple {

0 commit comments

Comments
 (0)