Skip to content
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

fix(multiple): fix focus and hover styles for mdc-checkbox and mdc-radio #24930

Merged
merged 2 commits into from
May 24, 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
13 changes: 10 additions & 3 deletions src/material-experimental/mdc-checkbox/_checkbox-private.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@use 'sass:map';
@use 'sass:color';
@use '@angular/material' as mat;
@use '@material/checkbox/checkbox-theme' as mdc-checkbox-theme;
@use '@material/theme/theme-color' as mdc-theme-color;

Expand All @@ -22,10 +23,16 @@ $private-checkbox-theme-config: map.merge(mdc-checkbox-theme.$light-theme, (

// Mixin that includes the checkbox theme styles with a given palette.
// By default, the MDC checkbox always uses the `secondary` palette.
@mixin private-checkbox-styles-with-color($color, $mdc-color) {
@mixin private-checkbox-styles-with-color($color-config, $color, $mdc-color) {
$is-dark: map-get($color-config, is-dark);
$on-surface: mdc-theme-color.prop-value(on-surface);
$border-color: rgba($on-surface, color.opacity(mdc-checkbox-theme.$border-color));
$disabled-color: rgba($on-surface, color.opacity(mdc-checkbox-theme.$disabled-color));
$active-border-color: if(
$is-dark,
mat.get-color-from-palette(mat.$gray-palette, 200),
mat.get-color-from-palette(mat.$gray-palette, 900)
);

@include mdc-checkbox-theme.theme((
selected-checkmark-color: mdc-theme-color.prop-value(on-#{$mdc-color}),
Expand All @@ -34,8 +41,8 @@ $private-checkbox-theme-config: map.merge(mdc-checkbox-theme.$light-theme, (
selected-hover-icon-color: $color,
selected-icon-color: $color,
selected-pressed-icon-color: $color,
unselected-focus-icon-color: $color,
unselected-hover-icon-color: $color,
unselected-focus-icon-color: $active-border-color,
unselected-hover-icon-color: $active-border-color,

disabled-selected-icon-color: $disabled-color,
disabled-unselected-icon-color: $disabled-color,
Expand Down
6 changes: 3 additions & 3 deletions src/material-experimental/mdc-checkbox/_checkbox-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@
// class for accent and warn style, and applying the appropriate overrides below. Since we
// don't use MDC's ripple, we also need to set the color for our replacement ripple.
&.mat-primary {
@include checkbox-private.private-checkbox-styles-with-color($primary, primary);
@include checkbox-private.private-checkbox-styles-with-color($config, $primary, primary);
@include _selected-ripple-colors($primary, primary);
}

&.mat-accent {
@include checkbox-private.private-checkbox-styles-with-color($accent, secondary);
@include checkbox-private.private-checkbox-styles-with-color($config, $accent, secondary);
@include _selected-ripple-colors($accent, secondary);
}

&.mat-warn {
@include checkbox-private.private-checkbox-styles-with-color($warn, error);
@include checkbox-private.private-checkbox-styles-with-color($config, $warn, error);
@include _selected-ripple-colors($warn, error);
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/material-experimental/mdc-checkbox/checkbox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@
display: none;
}

// We don't inherit the border focus style from MDC since we don't use their ripple.
// Instead we need to replicate it here.
.mdc-checkbox__native-control {
&:focus:enabled:not(:checked):not(:indeterminate):not([data-indeterminate=true]) {
& ~ .mdc-checkbox__background {
border-color: var(--mdc-checkbox-unselected-focus-icon-color, black);
}
}
}

@include _ripple-base-styles();
}

Expand Down
4 changes: 2 additions & 2 deletions src/material-experimental/mdc-list/_list-option-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// Mixin that overrides the selected item and checkbox colors for list options. By
// default, the MDC list uses the `primary` color for list items. The MDC checkbox
// inside list options by default uses the `primary` color too.
@mixin private-list-option-color-override($color, $mdc-color) {
@mixin private-list-option-color-override($color-config, $color, $mdc-color) {
& .mdc-list-item__start, & .mdc-list-item__end {
@include checkbox-private.private-checkbox-styles-with-color($color, $mdc-color);
@include checkbox-private.private-checkbox-styles-with-color($color-config, $color, $mdc-color);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/material-experimental/mdc-list/_list-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
@include mdc-list.without-ripple($query: mdc-helpers.$mat-theme-styles-query);

.mat-mdc-list-option {
@include list-option-theme.private-list-option-color-override($primary, primary);
@include list-option-theme.private-list-option-color-override($config, $primary, primary);
}
.mat-mdc-list-option.mat-accent {
@include list-option-theme.private-list-option-color-override($accent, secondary);
@include list-option-theme.private-list-option-color-override($config, $accent, secondary);
}
.mat-mdc-list-option.mat-warn {
@include list-option-theme.private-list-option-color-override($warn, error);
@include list-option-theme.private-list-option-color-override($config, $warn, error);
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/material-experimental/mdc-radio/_radio-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@

@include mdc-helpers.mat-using-mdc-theme($config) {
$on-surface: rgba(mdc-theme-color.$on-surface, 0.54);
$is-dark: map-get($config, is-dark);
$active-border-color: if(
$is-dark,
mat.get-color-from-palette(mat.$gray-palette, 200),
mat.get-color-from-palette(mat.$gray-palette, 900)
);

.mat-mdc-radio-button {
@include mdc-form-field.core-styles($query: mdc-helpers.$mat-theme-styles-query);
Expand All @@ -33,8 +39,8 @@
// MDC applies a separate opacity to disabled buttons.
disabled-selected-icon-color: mdc-theme-color.$on-surface,
disabled-unselected-icon-color: mdc-theme-color.$on-surface,
unselected-focus-icon-color: $on-surface,
unselected-hover-icon-color: $on-surface,
unselected-focus-icon-color: $active-border-color,
unselected-hover-icon-color: $active-border-color,
unselected-icon-color: $on-surface,
unselected-pressed-icon-color: $on-surface,
));
Expand Down
8 changes: 8 additions & 0 deletions src/material-experimental/mdc-radio/radio.scss
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@
transition: none !important;
}
}

// We don't inherit the border focus style from MDC since we don't use their ripple.
// Instead we need to replicate it here.
.mdc-radio .mdc-radio__native-control:focus:enabled:not(:checked) {
& ~ .mdc-radio__background .mdc-radio__outer-circle {
border-color: var(--mdc-radio-unselected-focus-icon-color, black);
}
}
}

// Element used to provide a larger tap target for users on touch devices.
Expand Down