Skip to content

Commit a7ee8a8

Browse files
committed
fix(multiple): fix focus and hover styles for mdc-checkbox and mdc-radio (#24930)
* fix(multiple): fix focus and hover styles for mdc-checkbox and mdc-radio * fix(multiple): address feedback (cherry picked from commit 5f5f9d6)
1 parent 7a3a195 commit a7ee8a8

File tree

7 files changed

+44
-13
lines changed

7 files changed

+44
-13
lines changed

src/material-experimental/mdc-checkbox/_checkbox-private.scss

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@use 'sass:map';
22
@use 'sass:color';
3+
@use '@angular/material' as mat;
34
@use '@material/checkbox/checkbox-theme' as mdc-checkbox-theme;
45
@use '@material/theme/theme-color' as mdc-theme-color;
56

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

2324
// Mixin that includes the checkbox theme styles with a given palette.
2425
// By default, the MDC checkbox always uses the `secondary` palette.
25-
@mixin private-checkbox-styles-with-color($color, $mdc-color) {
26+
@mixin private-checkbox-styles-with-color($color-config, $color, $mdc-color) {
27+
$is-dark: map-get($color-config, is-dark);
2628
$on-surface: mdc-theme-color.prop-value(on-surface);
2729
$border-color: rgba($on-surface, color.opacity(mdc-checkbox-theme.$border-color));
2830
$disabled-color: rgba($on-surface, color.opacity(mdc-checkbox-theme.$disabled-color));
31+
$active-border-color: if(
32+
$is-dark,
33+
mat.get-color-from-palette(mat.$gray-palette, 200),
34+
mat.get-color-from-palette(mat.$gray-palette, 900)
35+
);
2936

3037
@include mdc-checkbox-theme.theme((
3138
selected-checkmark-color: mdc-theme-color.prop-value(on-#{$mdc-color}),
@@ -34,8 +41,8 @@ $private-checkbox-theme-config: map.merge(mdc-checkbox-theme.$light-theme, (
3441
selected-hover-icon-color: $color,
3542
selected-icon-color: $color,
3643
selected-pressed-icon-color: $color,
37-
unselected-focus-icon-color: $color,
38-
unselected-hover-icon-color: $color,
44+
unselected-focus-icon-color: $active-border-color,
45+
unselected-hover-icon-color: $active-border-color,
3946

4047
disabled-selected-icon-color: $disabled-color,
4148
disabled-unselected-icon-color: $disabled-color,

src/material-experimental/mdc-checkbox/_checkbox-theme.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@
5252
// class for accent and warn style, and applying the appropriate overrides below. Since we
5353
// don't use MDC's ripple, we also need to set the color for our replacement ripple.
5454
&.mat-primary {
55-
@include checkbox-private.private-checkbox-styles-with-color($primary, primary);
55+
@include checkbox-private.private-checkbox-styles-with-color($config, $primary, primary);
5656
@include _selected-ripple-colors($primary, primary);
5757
}
5858

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

6464
&.mat-warn {
65-
@include checkbox-private.private-checkbox-styles-with-color($warn, error);
65+
@include checkbox-private.private-checkbox-styles-with-color($config, $warn, error);
6666
@include _selected-ripple-colors($warn, error);
6767
}
6868
}

src/material-experimental/mdc-checkbox/checkbox.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@
9090
display: none;
9191
}
9292

93+
// We don't inherit the border focus style from MDC since we don't use their ripple.
94+
// Instead we need to replicate it here.
95+
.mdc-checkbox__native-control {
96+
&:focus:enabled:not(:checked):not(:indeterminate):not([data-indeterminate=true]) {
97+
& ~ .mdc-checkbox__background {
98+
border-color: var(--mdc-checkbox-unselected-focus-icon-color, black);
99+
}
100+
}
101+
}
102+
93103
@include _ripple-base-styles();
94104
}
95105

src/material-experimental/mdc-list/_list-option-theme.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
// Mixin that overrides the selected item and checkbox colors for list options. By
77
// default, the MDC list uses the `primary` color for list items. The MDC checkbox
88
// inside list options by default uses the `primary` color too.
9-
@mixin private-list-option-color-override($color, $mdc-color) {
9+
@mixin private-list-option-color-override($color-config, $color, $mdc-color) {
1010
& .mdc-list-item__start, & .mdc-list-item__end {
11-
@include checkbox-private.private-checkbox-styles-with-color($color, $mdc-color);
11+
@include checkbox-private.private-checkbox-styles-with-color($color-config, $color, $mdc-color);
1212
}
1313
}
1414

src/material-experimental/mdc-list/_list-theme.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
@include mdc-list.without-ripple($query: mdc-helpers.$mat-theme-styles-query);
2222

2323
.mat-mdc-list-option {
24-
@include list-option-theme.private-list-option-color-override($primary, primary);
24+
@include list-option-theme.private-list-option-color-override($config, $primary, primary);
2525
}
2626
.mat-mdc-list-option.mat-accent {
27-
@include list-option-theme.private-list-option-color-override($accent, secondary);
27+
@include list-option-theme.private-list-option-color-override($config, $accent, secondary);
2828
}
2929
.mat-mdc-list-option.mat-warn {
30-
@include list-option-theme.private-list-option-color-override($warn, error);
30+
@include list-option-theme.private-list-option-color-override($config, $warn, error);
3131
}
3232
}
3333
}

src/material-experimental/mdc-radio/_radio-theme.scss

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626

2727
@include mdc-helpers.mat-using-mdc-theme($config) {
2828
$on-surface: rgba(mdc-theme-color.$on-surface, 0.54);
29+
$is-dark: map-get($config, is-dark);
30+
$active-border-color: if(
31+
$is-dark,
32+
mat.get-color-from-palette(mat.$gray-palette, 200),
33+
mat.get-color-from-palette(mat.$gray-palette, 900)
34+
);
2935

3036
.mat-mdc-radio-button {
3137
@include mdc-form-field.core-styles($query: mdc-helpers.$mat-theme-styles-query);
@@ -34,8 +40,8 @@
3440
// MDC applies a separate opacity to disabled buttons.
3541
disabled-selected-icon-color: mdc-theme-color.$on-surface,
3642
disabled-unselected-icon-color: mdc-theme-color.$on-surface,
37-
unselected-focus-icon-color: $on-surface,
38-
unselected-hover-icon-color: $on-surface,
43+
unselected-focus-icon-color: $active-border-color,
44+
unselected-hover-icon-color: $active-border-color,
3945
unselected-icon-color: $on-surface,
4046
unselected-pressed-icon-color: $on-surface,
4147
));

src/material-experimental/mdc-radio/radio.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@
7575
transition: none !important;
7676
}
7777
}
78+
79+
// We don't inherit the border focus style from MDC since we don't use their ripple.
80+
// Instead we need to replicate it here.
81+
.mdc-radio .mdc-radio__native-control:focus:enabled:not(:checked) {
82+
& ~ .mdc-radio__background .mdc-radio__outer-circle {
83+
border-color: var(--mdc-radio-unselected-focus-icon-color, black);
84+
}
85+
}
7886
}
7987

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

0 commit comments

Comments
 (0)