Skip to content

fix(material/button-toggle): use solid border color #14253

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 1 commit into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions src/material/button-toggle/_button-toggle-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
$foreground: map.get($config, foreground);
$background: map.get($config, background);
$divider-color: theming.get-color-from-palette($foreground, divider);
$theme-divider-color: map.get($foreground, divider);

// By default the theme usually has an rgba color for the dividers, which can
// stack up with the background of a button toggle. This can cause the border
// of a selected toggle to look different from an deselected one. We use a solid
// color to ensure that the border always stays the same.
$divider-color: if(type-of($theme-divider-color) == color,
theming.private-rgba-to-hex($theme-divider-color, map.get($background, card)),
$theme-divider-color
);

.mat-button-toggle-standalone,
.mat-button-toggle-group {
Expand Down
9 changes: 9 additions & 0 deletions src/material/core/theming/_theming.scss
Original file line number Diff line number Diff line change
Expand Up @@ -437,3 +437,12 @@ $_emitted-density: () !default;
color: $theme-or-color-config
));
}


// Approximates an rgba color into a solid hex color, given a background color.
@function private-rgba-to-hex($color, $background-color) {
// We convert the rgba color into a solid one by taking the opacity from the rgba
// value and using it to determine the percentage of the background to put
// into foreground when mixing the colors together.
@return mix($background-color, rgba($color, 1), (1 - opacity($color)) * 100%);
}