Skip to content

Commit c199aa2

Browse files
devversionmmalerba
authored andcommittedDec 17, 2021
fix(material-experimental/mdc-list): incorrect active/hover color for selected items
Fixes that the active/hover color for selected list-options (in single-selection mode) does not match up with what the MDC-list renders. The current effect is a little confusing visually.
1 parent 417f689 commit c199aa2

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed
 

‎src/material-experimental/mdc-list/_interactive-list-theme.scss

+17-11
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,27 @@
1414
background: $active-base-color;
1515
}
1616

17-
&.mdc-list-item--selected::before {
18-
background: $selected-color;
19-
opacity: mdc-ripple.states-opacity($selected-color, selected);
17+
&:not(:focus):not(.mdc-list-item--disabled):hover::before {
18+
opacity: mdc-ripple.states-opacity($active-base-color, hover);
2019
}
2120

22-
&:focus::before {
23-
opacity: mdc-ripple.states-opacity($active-base-color, focus);
21+
&.mdc-list-item--selected {
22+
&::before {
23+
background: $selected-color;
24+
opacity: mdc-ripple.states-opacity($selected-color, selected);
25+
}
26+
27+
&:not(:focus):not(.mdc-list-item--disabled):hover::before {
28+
// The hover and selected opacities need to be combined to match with what the MDC
29+
// ripple state would render. More details here:
30+
// https://github.com/material-components/material-components-web/blob/348665978ce73694ad4518626dd70cdf5b984113/packages/mdc-ripple/_ripple-theme.scss#L450.
31+
opacity: mdc-ripple.states-opacity($selected-color, hover) +
32+
mdc-ripple.states-opacity($selected-color, selected);
33+
}
2434
}
25-
}
2635

27-
// MDC still shows focus/selected state if the item is disabled.
28-
// Just hover styles should not show up for disabled items.
29-
.mat-mdc-list-item-interactive:not(.mdc-list-item--disabled):not(.mdc-list-item--selected) {
30-
&:not(:focus):hover::before {
31-
opacity: mdc-ripple.states-opacity($active-base-color, hover);
36+
&:focus::before {
37+
opacity: mdc-ripple.states-opacity($active-base-color, focus);
3238
}
3339
}
3440
}

0 commit comments

Comments
 (0)
Please sign in to comment.