Skip to content

Commit b6e0b20

Browse files
authored
fix(material-experimental/theming): Fix chip trailing icon opacity in M3 (#28530)
1 parent 32f86e4 commit b6e0b20

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

src/material-experimental/theming/_custom-tokens.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@
206206
map.get($systems, md-sys-state, hover-state-layer-opacity),
207207
trailing-action-focus-state-layer-opacity:
208208
map.get($systems, md-sys-state, focus-state-layer-opacity),
209+
trailing-action-opacity: _hardcode(1, $exclude-hardcoded),
210+
trailing-action-focus-opacity: _hardcode(1, $exclude-hardcoded),
209211
), (
210212
primary: (
211213
selected-trailing-icon-color: map.get($systems, md-sys-color, on-primary-container),
@@ -278,6 +280,7 @@
278280
selected-focus-state-layer-opacity:
279281
map.get($systems, md-sys-state, focus-state-layer-opacity),
280282
with-icon-disabled-icon-opacity: _hardcode(0.38, $exclude-hardcoded),
283+
with-trailing-icon-disabled-trailing-icon-opacity: _hardcode(0.38, $exclude-hardcoded),
281284
),
282285
), (
283286
// Color variants:

src/material/chips/chip.scss

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
}
2424

2525
// Add additional slots for the MDC chip tokens, needed in Angular Material.
26+
$disabled-trailing-icon-opacity: 1;
27+
2628
@include token-utils.use-tokens(tokens-mdc-chip.$prefix, $mdc-chip-token-slots) {
2729
.mat-mdc-chip-focus-overlay {
2830
@include token-utils.create-token-slot(background, focus-state-layer-color);
@@ -56,6 +58,14 @@
5658
@include token-utils.create-token-slot(opacity, with-avatar-disabled-avatar-opacity);
5759
}
5860

61+
.mdc-evolution-chip--disabled .mdc-evolution-chip__icon--trailing {
62+
$disabled-trailing-icon-opacity:
63+
token-utils.get-token-variable(with-trailing-icon-disabled-trailing-icon-opacity);
64+
65+
@include token-utils.create-token-slot(
66+
opacity, with-trailing-icon-disabled-trailing-icon-opacity);
67+
}
68+
5969
.mdc-evolution-chip--disabled.mdc-evolution-chip--selected .mdc-evolution-chip__checkmark {
6070
@include token-utils.create-token-slot(opacity, with-icon-disabled-icon-opacity);
6171
}
@@ -81,6 +91,12 @@
8191
}
8292

8393
.mat-mdc-chip-remove {
94+
@include token-utils.create-token-slot(opacity, trailing-action-opacity);
95+
96+
&:focus {
97+
@include token-utils.create-token-slot(opacity, trailing-action-focus-opacity);
98+
}
99+
84100
&::after {
85101
@include token-utils.create-token-slot(background, trailing-action-state-layer-color);
86102
}
@@ -98,6 +114,24 @@
98114
@include token-utils.create-token-slot(
99115
background, selected-trailing-action-state-layer-color);
100116
}
117+
118+
// If the trailing icon is a chip-remove button, we have to factor in the trailing action
119+
// opacity as well as the disabled opacity.
120+
.mdc-evolution-chip--disabled .mdc-evolution-chip__icon--trailing {
121+
&.mat-mdc-chip-remove {
122+
opacity: calc(
123+
var(#{token-utils.get-token-variable(trailing-action-opacity)}) *
124+
var(#{$disabled-trailing-icon-opacity})
125+
);
126+
127+
&:focus {
128+
opacity: calc(
129+
var(#{token-utils.get-token-variable(trailing-action-focus-opacity)}) *
130+
var(#{$disabled-trailing-icon-opacity})
131+
);
132+
}
133+
}
134+
}
101135
}
102136
}
103137

@@ -307,14 +341,6 @@
307341
}
308342

309343
.mat-mdc-chip-remove {
310-
// Fades out the trailing icon slightly so that it can become darker when focused.
311-
// The MDC theming has variables for this, but the focus/hover states don't seem to work.
312-
opacity: 0.54;
313-
314-
&:focus {
315-
opacity: 1;
316-
}
317-
318344
&::before {
319345
$default-border-width: focus-indicators-private.$default-border-width;
320346
$offset: var(--mat-mdc-focus-indicator-border-width, #{$default-border-width});

src/material/core/tokens/m2/mat/_chip.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ $prefix: (mat, chip);
1212
@function get-unthemable-tokens() {
1313
@return (
1414
disabled-container-opacity: 0.4,
15+
trailing-action-opacity: 0.54,
16+
trailing-action-focus-opacity: 1,
1517
trailing-action-state-layer-color: transparent,
1618
selected-trailing-action-state-layer-color: transparent,
1719
trailing-action-hover-state-layer-opacity: 0,

src/material/core/tokens/m2/mdc/_chip.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ $prefix: (mdc, chip);
5555
flat-selected-outline-width: 0,
5656
// The opacity of the chip's state overlay when selected and hovered.
5757
selected-hover-state-layer-opacity: 0.04,
58+
// The opacity of the chip's trailing icon when it is disabled.
59+
with-trailing-icon-disabled-trailing-icon-opacity: 1,
5860
// The opacity of the chip's leading icon when it is disabled.
5961
with-icon-disabled-icon-opacity: 1,
6062
// Not used by MDC.
@@ -76,8 +78,6 @@ $prefix: (mdc, chip);
7678
// Not used by MDC.
7779
with-leading-icon-leading-icon-size: null,
7880
// Not used by MDC.
79-
with-trailing-icon-disabled-trailing-icon-opacity: null,
80-
// Not used by MDC.
8181
with-trailing-icon-trailing-icon-size: null,
8282
// Elevated chips not implemented.
8383
container-elevation: null,

0 commit comments

Comments
 (0)