Skip to content

Commit 271490d

Browse files
authored
fix(material/chips): highlighted not working in M3 (#29001)
Remaps some of the tokens so that the `highlighted` input can work in M3. Fixes #28923.
1 parent 9bdf640 commit 271490d

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

src/material/chips/chip.scss

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,35 @@
2222
@include mdc-chip-theme.theme-styles($mdc-chip-token-slots);
2323
}
2424

25+
// The highlighted attribute is used to make the chip appear as selected on-demand,
26+
// aside from showing the selected indicator. We achieve this by re-mapping the base
27+
// tokens to the highlighted ones. Note that we only need to do this for the tokens
28+
// that we don't re-implement ourselves below.
29+
// TODO(crisbeto): with some future refactors we may be able to clean this up.
30+
.mat-mdc-chip-highlighted {
31+
@include token-utils.use-tokens(tokens-mdc-chip.$prefix, $mdc-chip-token-slots) {
32+
$highlighted-remapped-tokens: (
33+
with-icon-icon-color: with-icon-selected-icon-color,
34+
elevated-container-color: elevated-selected-container-color,
35+
label-text-color: selected-label-text-color,
36+
outline-width: flat-selected-outline-width,
37+
);
38+
39+
@each $selected, $base in $highlighted-remapped-tokens {
40+
#{token-utils.get-token-variable($selected)}: var(token-utils.get-token-variable($base));
41+
}
42+
}
43+
}
44+
2545
// Add additional slots for the MDC chip tokens, needed in Angular Material.
2646
$disabled-trailing-icon-opacity: 1;
2747

2848
@include token-utils.use-tokens(tokens-mdc-chip.$prefix, $mdc-chip-token-slots) {
2949
.mat-mdc-chip-focus-overlay {
3050
@include token-utils.create-token-slot(background, focus-state-layer-color);
3151

32-
.mat-mdc-chip-selected & {
52+
.mat-mdc-chip-selected &,
53+
.mat-mdc-chip-highlighted & {
3354
@include token-utils.create-token-slot(background, selected-focus-state-layer-color);
3455
}
3556

@@ -38,7 +59,8 @@
3859
@include token-utils.create-token-slot(opacity, hover-state-layer-opacity);
3960
}
4061

41-
.mat-mdc-chip-selected:hover & {
62+
.mat-mdc-chip-selected:hover,
63+
.mat-mdc-chip-highlighted:hover & {
4264
@include token-utils.create-token-slot(background, selected-hover-state-layer-color);
4365
@include token-utils.create-token-slot(opacity, selected-hover-state-layer-opacity);
4466
}
@@ -48,7 +70,8 @@
4870
@include token-utils.create-token-slot(opacity, focus-state-layer-opacity);
4971
}
5072

51-
.mat-mdc-chip-selected.cdk-focused & {
73+
.mat-mdc-chip-selected.cdk-focused &,
74+
.mat-mdc-chip-highlighted.cdk-focused & {
5275
@include token-utils.create-token-slot(background, selected-focus-state-layer-color);
5376
@include token-utils.create-token-slot(opacity, selected-focus-state-layer-opacity);
5477
}
@@ -79,7 +102,8 @@
79102
@include token-utils.create-token-slot(opacity, disabled-container-opacity);
80103
}
81104

82-
&.mdc-evolution-chip--selected {
105+
&.mdc-evolution-chip--selected,
106+
&.mat-mdc-chip-highlighted {
83107
.mdc-evolution-chip__icon--trailing {
84108
@include token-utils.create-token-slot(color, selected-trailing-icon-color);
85109
}
@@ -110,7 +134,8 @@
110134
}
111135
}
112136

113-
.mat-mdc-chip-selected .mat-mdc-chip-remove::after {
137+
.mat-mdc-chip-selected .mat-mdc-chip-remove::after,
138+
.mat-mdc-chip-highlighted .mat-mdc-chip-remove::after {
114139
@include token-utils.create-token-slot(
115140
background, selected-trailing-action-state-layer-color);
116141
}

0 commit comments

Comments
 (0)