Skip to content

Commit 0b653df

Browse files
devversionvictoriaaa234
authored andcommitted
fix(slide-toggle): no color demarcation in high contrast black mode (#12150)
* Fixes that there is no way to identify a checked slide-toggle in high contrast mode. * Fixes that the slide-toggle bar is not visible in high-contrast mode white. * Moves high contrast CSS to the end of the SCSS file in order to separate normal styles that are required for the slide-toggle from the high contrast custom CSS.
1 parent 3f769c1 commit 0b653df

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

src/lib/slide-toggle/slide-toggle.scss

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,6 @@ $mat-slide-toggle-bar-track-width: $mat-slide-toggle-bar-width - $mat-slide-togg
125125
border-radius: 50%;
126126

127127
@include mat-elevation(1);
128-
129-
@include cdk-high-contrast {
130-
background: #fff;
131-
border: solid 1px #000;
132-
}
133128
}
134129

135130
// Horizontal bar for the slide-toggle.
@@ -145,10 +140,6 @@ $mat-slide-toggle-bar-track-width: $mat-slide-toggle-bar-width - $mat-slide-togg
145140
flex-shrink: 0;
146141

147142
border-radius: $mat-slide-toggle-bar-border-radius;
148-
149-
@include cdk-high-contrast {
150-
background: #fff;
151-
}
152143
}
153144

154145
// The slide toggle shows a visually hidden input inside of the component, which is used
@@ -181,3 +172,28 @@ $mat-slide-toggle-bar-track-width: $mat-slide-toggle-bar-width - $mat-slide-togg
181172
z-index: 1;
182173
pointer-events: none;
183174
}
175+
176+
/** Custom styling to make the slide-toggle usable in high contrast mode. */
177+
@include cdk-high-contrast() {
178+
.mat-slide-toggle-thumb {
179+
background: #fff;
180+
border: 1px solid #000;
181+
182+
.mat-slide-toggle.mat-checked & {
183+
background: #000;
184+
border: 1px solid #fff;
185+
}
186+
}
187+
188+
.mat-slide-toggle-bar {
189+
background: #fff;
190+
}
191+
}
192+
193+
// Since the bar with a white background will be placed on a white background, we need to a black
194+
// border in order to make sure that the bar is visible.
195+
@include cdk-high-contrast(black-on-white) {
196+
.mat-slide-toggle-bar {
197+
border: 1px solid #000;
198+
}
199+
}

0 commit comments

Comments
 (0)