Skip to content

Commit 82f4560

Browse files
devversionandrewseguin
authored andcommitted
refactor: move high-contrast style for button-toggle out of density
Moves the high-contrast style for standard button-toggles from the density mixin to the base component styles. We previously moved the high contrast style into the density mixin, but that is not stricly necessary as the border width can be set to a value that is larger than common button-toggles. The benefit is that this style can remain in the base component styles and doesn't need to be generated for each density level. This came up when we added backwards compatibility logic for the density API. The high-contrast code uses `@at-root`, while the density API intends to use that in some situations too. These nested `@at-root` statements will not work as expected because the high contrast mixin relies on the parent selector (ampersand) that is causing the density `@at-root` to be a noop basically. See: https://www.sassmeister.com/gist/b167ceb6b6d30c8c8c8db1580bce728d.
1 parent 90ba6a4 commit 82f4560

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/material/button-toggle/_button-toggle-theme.scss

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,6 @@
101101
.mat-button-toggle-appearance-standard .mat-button-toggle-label-content {
102102
line-height: $standard-height;
103103
}
104-
105-
@include cdk-high-contrast(active, off) {
106-
.mat-button-toggle-checked.mat-button-toggle-appearance-standard
107-
.mat-button-toggle-focus-overlay {
108-
border-bottom: solid $standard-height;
109-
}
110-
}
111104
}
112105
}
113106

src/material/button-toggle/button-toggle.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,17 @@ $mat-button-toggle-legacy-border-radius: 2px !default;
133133
}
134134
}
135135

136+
@include cdk-high-contrast(active, off) {
137+
.mat-button-toggle-checked.mat-button-toggle-appearance-standard
138+
.mat-button-toggle-focus-overlay {
139+
// In high contrast mode, we use a border for the checked state because backgrounds
140+
// can either be opaque or transparent. We set the border height to a value that is larger
141+
// than usual button toggles are. This allows us to keep this high contrast style in the
142+
// base component style, instead of making it dependent on height determined through density.
143+
border-bottom: solid 500px;
144+
}
145+
}
146+
136147
// Increase specificity because ripple styles are part of the `mat-core` mixin and can
137148
// potentially overwrite the absolute position of the container.
138149
.mat-button-toggle .mat-button-toggle-ripple {

0 commit comments

Comments
 (0)