Skip to content

Commit 5f5f9d6

Browse files
authored
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
1 parent 445134c commit 5f5f9d6

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
@@ -51,17 +51,17 @@
5151
// class for accent and warn style, and applying the appropriate overrides below. Since we
5252
// don't use MDC's ripple, we also need to set the color for our replacement ripple.
5353
&.mat-primary {
54-
@include checkbox-private.private-checkbox-styles-with-color($primary, primary);
54+
@include checkbox-private.private-checkbox-styles-with-color($config, $primary, primary);
5555
@include _selected-ripple-colors($primary, primary);
5656
}
5757

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

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

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
@@ -19,13 +19,13 @@
1919
@include mdc-list.without-ripple($query: mdc-helpers.$mat-theme-styles-query);
2020

2121
.mat-mdc-list-option {
22-
@include list-option-theme.private-list-option-color-override($primary, primary);
22+
@include list-option-theme.private-list-option-color-override($config, $primary, primary);
2323
}
2424
.mat-mdc-list-option.mat-accent {
25-
@include list-option-theme.private-list-option-color-override($accent, secondary);
25+
@include list-option-theme.private-list-option-color-override($config, $accent, secondary);
2626
}
2727
.mat-mdc-list-option.mat-warn {
28-
@include list-option-theme.private-list-option-color-override($warn, error);
28+
@include list-option-theme.private-list-option-color-override($config, $warn, error);
2929
}
3030
}
3131
}

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

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

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

2935
.mat-mdc-radio-button {
3036
@include mdc-form-field.core-styles($query: mdc-helpers.$mat-theme-styles-query);
@@ -33,8 +39,8 @@
3339
// MDC applies a separate opacity to disabled buttons.
3440
disabled-selected-icon-color: mdc-theme-color.$on-surface,
3541
disabled-unselected-icon-color: mdc-theme-color.$on-surface,
36-
unselected-focus-icon-color: $on-surface,
37-
unselected-hover-icon-color: $on-surface,
42+
unselected-focus-icon-color: $active-border-color,
43+
unselected-hover-icon-color: $active-border-color,
3844
unselected-icon-color: $on-surface,
3945
unselected-pressed-icon-color: $on-surface,
4046
));

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

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

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

0 commit comments

Comments
 (0)