Skip to content

Commit fbf0ab5

Browse files
committed
fix(material/chips): adjust focus state layer color
Adjust the color of the focus state layer in light mode. Set the focus state color in light mode to the 700 hue of the primary color palette. Use tokens to adjust the color. Does not affect dark mode.
1 parent 2f992e9 commit fbf0ab5

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

src/material/chips/_chips-theme.scss

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
@function _get-default-palette($config) {
1212
$is-dark: map.get($config, is-dark);
1313
$grey-50: map.get(palette.$grey-palette, 50);
14+
$grey-200: map.get(palette.$grey-palette, 200);
15+
$grey-800: map.get(palette.$grey-palette, 800);
1416
$grey-900: map.get(palette.$grey-palette, 900);
1517
$default-foreground: if($is-dark, $grey-50, $grey-900);
1618

@@ -26,7 +28,17 @@
2628
$on-surface
2729
);
2830

29-
@return (default: $default-background, default-contrast: $default-foreground);
31+
$default-darker: if(
32+
mdc-helpers.variable-safe-contrast-tone($surface, $is-dark) == 'dark',
33+
$grey-800,
34+
$grey-200,
35+
);
36+
37+
@return (
38+
default: $default-background,
39+
default-contrast: $default-foreground,
40+
darker: $default-darker,
41+
);
3042
}
3143

3244
@mixin color($config-or-theme) {
@@ -58,10 +70,6 @@
5870
}
5971
}
6072
}
61-
62-
.mat-mdc-chip-focus-overlay {
63-
background: map.get(map.get($config, foreground), base);
64-
}
6573
}
6674

6775
@mixin typography($config-or-theme) {

src/material/chips/chip.scss

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
@use '../core/style/layout-common';
66
@use '../core/focus-indicators/private' as focus-indicators-private;
77
@use '../core/tokens/m2/mdc/chip' as m2-mdc-chip;
8+
@use '../core/tokens/token-utils';
89
@use '@material/theme/custom-properties' as mdc-custom-properties;
910

1011
// The slots for tokens that will be configured in the theme can be emitted with no fallback.
@@ -21,6 +22,14 @@
2122
// Add default values for tokens that aren't outputted by the theming API.
2223
@include mdc-chip-theme.theme(m2-mdc-chip.get-unthemable-tokens());
2324
}
25+
26+
// Add additional slots for the MDC chip tokens, needed in Angular Material.
27+
@include token-utils.use-tokens(m2-mdc-chip.$prefix, $token-slots) {
28+
.mat-mdc-chip-focus-overlay {
29+
@include token-utils.create-token-slot(background, focus-state-layer-color);
30+
@include token-utils.create-token-slot(opacity, focus-state-layer-opacity);
31+
}
32+
}
2433
}
2534

2635
// We *should* be able to include these styles through MDC's
@@ -294,4 +303,4 @@
294303
// a separate element, rather than on the focusable element itself.
295304
.mat-mdc-chip-action:focus .mat-mdc-focus-indicator::before {
296305
content: '';
297-
}
306+
}

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,6 @@ $prefix: (mdc, chip);
135135
// Unused.
136136
focus-outline-color: null,
137137
// Unused.
138-
focus-state-layer-color: null,
139-
// Unused.
140-
focus-state-layer-opacity: null,
141-
// Unused.
142138
hover-label-text-color: null,
143139
// Unused.
144140
hover-state-layer-color: null,
@@ -233,9 +229,19 @@ $prefix: (mdc, chip);
233229

234230
// Tokens that can be configured through Angular Material's color theming API.
235231
@function get-color-tokens($config) {
232+
$is-dark: map.get($config, is-dark);
236233
$palette: map.get($config, primary);
234+
237235
$background: theming.get-color-from-palette($palette);
238236
$foreground: theming.get-color-from-palette($palette, default-contrast);
237+
$darker: theming.get-color-from-palette($palette, darker);
238+
239+
$state-layer-color: if(
240+
$is-dark,
241+
theming.get-color-from-palette(map.get($config, foreground), base),
242+
$darker,
243+
);
244+
$state-layer-opacity: 0.12; // 0.12 is a common Material Design value for opacity.
239245

240246
@return (
241247
// The text color of a disabled chip.
@@ -244,6 +250,10 @@ $prefix: (mdc, chip);
244250
elevated-container-color: $background,
245251
// The background-color of a disabled chip.
246252
elevated-disabled-container-color: $background,
253+
// The color of the focus state layer.
254+
focus-state-layer-color: $state-layer-color,
255+
// The opacity of the focus state layer.
256+
focus-state-layer-opacity: $state-layer-opacity,
247257
// The chip text color.
248258
label-text-color: $foreground,
249259
// The icon color of a chip.

0 commit comments

Comments
 (0)