Skip to content

Commit 175937e

Browse files
authored
fix(material/button-toggle): use solid border color (#14253)
Usually the theme divider color is rgba, which means that it can look differently, depending on the color behind it. As a result, the border of a selected button toggle is different from a deselected one, because its background color is darker. These changes switch to using a solid color to ensure that we have always have a consistent border. These changes also add a new theming utility function that converts an rgba color to hex, if the consumer knows the background. We've been using it in a couple of places already, but now it's being moved out into a reusable function.
1 parent 50efb92 commit 175937e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

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

+10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@
1111
$foreground: map.get($config, foreground);
1212
$background: map.get($config, background);
1313
$divider-color: theming.get-color-from-palette($foreground, divider);
14+
$theme-divider-color: map.get($foreground, divider);
15+
16+
// By default the theme usually has an rgba color for the dividers, which can
17+
// stack up with the background of a button toggle. This can cause the border
18+
// of a selected toggle to look different from an deselected one. We use a solid
19+
// color to ensure that the border always stays the same.
20+
$divider-color: if(type-of($theme-divider-color) == color,
21+
theming.private-rgba-to-hex($theme-divider-color, map.get($background, card)),
22+
$theme-divider-color
23+
);
1424

1525
.mat-button-toggle-standalone,
1626
.mat-button-toggle-group {

src/material/core/theming/_theming.scss

+9
Original file line numberDiff line numberDiff line change
@@ -437,3 +437,12 @@ $_emitted-density: () !default;
437437
color: $theme-or-color-config
438438
));
439439
}
440+
441+
442+
// Approximates an rgba color into a solid hex color, given a background color.
443+
@function private-rgba-to-hex($color, $background-color) {
444+
// We convert the rgba color into a solid one by taking the opacity from the rgba
445+
// value and using it to determine the percentage of the background to put
446+
// into foreground when mixing the colors together.
447+
@return mix($background-color, rgba($color, 1), (1 - opacity($color)) * 100%);
448+
}

0 commit comments

Comments
 (0)