Skip to content

Commit 7957423

Browse files
crisbetommalerba
authored andcommitted
fix(material-experimental/mdc-chips): align theming setup with… (#19000)
Fixes the MDC-based chips not wrapping its styles in `mat-using-mdc-theme` and not overriding the MDC theme variables with our context.
1 parent 58abf23 commit 7957423

File tree

1 file changed

+35
-17
lines changed

1 file changed

+35
-17
lines changed

src/material-experimental/mdc-chips/_chips-theme.scss

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,55 @@
33
@import '@material/theme/functions.import';
44

55
@mixin mat-mdc-chips-theme($theme) {
6-
@include mdc-chip-set-core-styles($query: $mat-theme-styles-query);
7-
@include mdc-chip-without-ripple($query: $mat-theme-styles-query);
8-
96
$primary: mat-color(map-get($theme, primary));
107
$accent: mat-color(map-get($theme, accent));
118
$warn: mat-color(map-get($theme, warn));
129
$background: map-get($theme, background);
1310
$unselected-background: mat-color($background, unselected-chip);
1411

15-
.mat-mdc-chip {
16-
@include mdc-chip-fill-color-accessible($unselected-background,
17-
$query: $mat-theme-styles-query);
12+
// Save original values of MDC global variables. We need to save these so we can restore the
13+
// variables to their original values and prevent unintended side effects from using this mixin.
14+
$orig-mdc-chips-fill-color-default: $mdc-chips-fill-color-default;
15+
$orig-mdc-chips-ink-color-default: $mdc-chips-ink-color-default;
16+
$orig-mdc-chips-icon-color: $mdc-chips-icon-color;
17+
18+
@include mat-using-mdc-theme($theme) {
19+
$mdc-chips-fill-color-default:
20+
mix(mdc-theme-prop-value(on-surface), mdc-theme-prop-value(surface), 12%) !global;
21+
$mdc-chips-ink-color-default: rgba(mdc-theme-prop-value(on-surface), 0.87) !global;
22+
$mdc-chips-icon-color: mdc-theme-prop-value(on-surface) !global;
23+
24+
@include mdc-chip-set-core-styles($query: $mat-theme-styles-query);
25+
@include mdc-chip-without-ripple($query: $mat-theme-styles-query);
26+
27+
.mat-mdc-chip {
28+
@include mdc-chip-fill-color-accessible($unselected-background,
29+
$query: $mat-theme-styles-query);
1830

19-
&.mat-primary {
20-
&.mdc-chip--selected, &.mat-mdc-chip-highlighted {
21-
@include mdc-chip-fill-color-accessible($primary, $query: $mat-theme-styles-query);
31+
&.mat-primary {
32+
&.mdc-chip--selected, &.mat-mdc-chip-highlighted {
33+
@include mdc-chip-fill-color-accessible($primary, $query: $mat-theme-styles-query);
34+
}
2235
}
23-
}
2436

25-
&.mat-accent {
26-
&.mdc-chip--selected, &.mat-mdc-chip-highlighted {
27-
@include mdc-chip-fill-color-accessible($accent, $query: $mat-theme-styles-query);
37+
&.mat-accent {
38+
&.mdc-chip--selected, &.mat-mdc-chip-highlighted {
39+
@include mdc-chip-fill-color-accessible($accent, $query: $mat-theme-styles-query);
40+
}
2841
}
29-
}
3042

31-
&.mat-warn {
32-
&.mdc-chip--selected, &.mat-mdc-chip-highlighted {
33-
@include mdc-chip-fill-color-accessible($warn, $query: $mat-theme-styles-query);
43+
&.mat-warn {
44+
&.mdc-chip--selected, &.mat-mdc-chip-highlighted {
45+
@include mdc-chip-fill-color-accessible($warn, $query: $mat-theme-styles-query);
46+
}
3447
}
3548
}
3649
}
50+
51+
// Restore original values of MDC global variables.
52+
$mdc-chips-fill-color-default: $orig-mdc-chips-fill-color-default !global;
53+
$mdc-chips-ink-color-default: $orig-mdc-chips-ink-color-default !global;
54+
$mdc-chips-icon-color: $orig-mdc-chips-icon-color !global;
3755
}
3856

3957
@mixin mat-mdc-chips-typography($config) {

0 commit comments

Comments
 (0)