Skip to content

fix(slide-toggle): fix and simplify high contrast styles #18104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 9 additions & 26 deletions src/material/slide-toggle/slide-toggle.scss
Original file line number Diff line number Diff line change
Expand Up @@ -217,34 +217,17 @@ $mat-slide-toggle-bar-track-width: $mat-slide-toggle-bar-width - $mat-slide-togg
}

/** Custom styling to make the slide-toggle usable in high contrast mode. */
@include cdk-high-contrast() {
.mat-slide-toggle-thumb {
background: #fff;
border: 1px solid #000;

.mat-slide-toggle.mat-checked & {
background: #000;
border: 1px solid #fff;
}
}

@include cdk-high-contrast {
.mat-slide-toggle-thumb,
.mat-slide-toggle-bar {
background: #fff;

// As a focus indication in high contrast mode, we add a dotted outline to the slide-toggle
// bar. Since the bar element does not have any padding, we need to specify an outline offset
// because otherwise the opaque thumb element will hide the outline.
.mat-slide-toggle.cdk-keyboard-focused & {
outline: 1px dotted;
outline-offset: ($mat-slide-toggle-height - $mat-slide-toggle-bar-height) / 2;
}
border: 1px solid;
}
}

// Since the bar with a white background will be placed on a white background, we need to a black
// border in order to make sure that the bar is visible.
@include cdk-high-contrast(black-on-white) {
.mat-slide-toggle-bar {
border: 1px solid #000;
// As a focus indication in high contrast mode, we add a dotted outline to the slide-toggle
// bar. Since the bar element does not have any padding, we need to specify an outline offset
// because otherwise the opaque thumb element will hide the outline.
.mat-slide-toggle.cdk-keyboard-focused .mat-slide-toggle-bar {
outline: 2px dotted;
outline-offset: ($mat-slide-toggle-height - $mat-slide-toggle-bar-height) / 2;
}
}