Skip to content

Commit b922da0

Browse files
committed
fix(material-experimental/mdc-radio): add hover indication
Fixes that the MDC-based radio button doesn't have hover indication, because it usually comes from the MDC ripple which we don't use.
1 parent cbef92a commit b922da0

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
));
1717

1818
// TODO(crisbeto): this should be included by MDC's `theme-styles`, but it isn't currently.
19-
@include mdc-radio-theme.focus-indicator-color($color-palette);
19+
&.mat-mdc-radio-checked {
20+
--mat-mdc-radio-ripple-color: #{$color-palette};
21+
}
2022
}
2123

2224
@mixin color($config-or-theme) {
@@ -41,6 +43,8 @@
4143
unselected-pressed-icon-color: $on-surface,
4244
));
4345

46+
--mat-mdc-radio-ripple-color: #{mdc-theme-color.prop-value(on-surface)};
47+
4448
&.mat-primary {
4549
@include _color-palette($primary);
4650
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
@use '@material/radio/radio-theme' as mdc-radio-theme;
44
@use '@material/form-field' as mdc-form-field;
55
@use '@material/touch-target' as mdc-touch-target;
6+
@use '@material/ripple' as mdc-ripple;
67
@use '../mdc-helpers/mdc-helpers';
78
@use '../../cdk/a11y';
89
@use '../../material/core/style/layout-common';
@@ -33,6 +34,18 @@
3334
unselected-pressed-state-layer-color: null,
3435
unselected-pressed-state-layer-opacity: null,
3536
)));
37+
38+
// TODO(crisbeto): this should be included by MDC's `theme-styles`, but it isn't currently.
39+
@include mdc-radio-theme.focus-indicator-color(
40+
var(--mat-mdc-radio-ripple-color, transparent));
41+
}
42+
43+
// MDC's hover indication comes from their ripple which we don't use.
44+
&:hover .mdc-radio__native-control:not([disabled]):not(:focus) {
45+
& ~ .mdc-radio__background::before {
46+
opacity: map.get(mdc-ripple.$dark-ink-opacities, hover);
47+
transform: scale(1);
48+
}
3649
}
3750
}
3851

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export class MatRadioGroup extends _MatRadioGroupBase<MatRadioButton> {
9090
'[class.mat-primary]': 'color === "primary"',
9191
'[class.mat-accent]': 'color === "accent"',
9292
'[class.mat-warn]': 'color === "warn"',
93+
'[class.mat-mdc-radio-checked]': 'checked',
9394
'[class._mat-animation-noopable]': '_noopAnimations',
9495
// Needs to be removed since it causes some a11y issues (see #21266).
9596
'[attr.tabindex]': 'null',

0 commit comments

Comments
 (0)