Skip to content

Commit 5f1a7ea

Browse files
authored
fix(material-experimental/theming): resolve M3 issues in mat-option (#28482)
Fixes the following issues in the M3 `mat-option`: * Font size was too small and font weight too high. This appears to have been a bug in the spec that MDC is also working around. These changes apply the same workaround as MDC. * Multi-select options in the selected state had a darker background, even though they shouldn't. This happened to work by accident in M2 and only became visible now in M3.
1 parent d963df9 commit 5f1a7ea

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -822,9 +822,7 @@
822822
/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values
823823
/// @return {Map} A set of custom tokens for the mat-option
824824
@function option($systems, $exclude-hardcoded) {
825-
@return (mat.private-merge-all(
826-
_generate-typography-tokens($systems, label-text, label-large),
827-
(
825+
@return ((
828826
selected-state-label-text-color: map.get($systems, md-sys-color, on-secondary-container),
829827
label-text-color: map.get($systems, md-sys-color, on-surface),
830828
hover-state-layer-color: mat.private-safe-color-change(
@@ -836,7 +834,17 @@
836834
$alpha: map.get($systems, md-sys-state, focus-state-layer-opacity)
837835
),
838836
selected-state-layer-color: map.get($systems, md-sys-color, secondary-container),
839-
),
837+
838+
// According to the spec the options have to be `label-large` in all typography
839+
// dimensions, however this is inconsistent with the designs and with MDC's
840+
// own implementation. This appears to be a bug in the spec, because MDC overrides
841+
// the font size and weight to be `body-large` (see b/261838263). We make the same
842+
// override here so the label looks correct.
843+
label-text-size: map.get($systems, md-sys-typescale, body-large-size),
844+
label-text-weight: map.get($systems, md-sys-typescale, body-large-weight),
845+
label-text-font: map.get($systems, md-sys-typescale, label-large-font),
846+
label-text-line-height: map.get($systems, md-sys-typescale, label-large-line-height),
847+
label-text-tracking: map.get($systems, md-sys-typescale, label-large-tracking),
840848
), (
841849
// Color variants:
842850
primary: (

src/material/core/option/option.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
@use '@material/typography/typography' as mdc-typography;
66

77
@use '../tokens/m2/mat/option' as tokens-mat-option;
8+
@use '../tokens/m2/mdc/list' as tokens-mdc-list;
89
@use '../tokens/token-utils';
910
@use '../mdc-helpers/mdc-helpers';
1011
@use '../style/vendor-prefixes';
@@ -178,6 +179,18 @@
178179
}
179180
}
180181

182+
.mat-mdc-option-multiple {
183+
// Multi-select options in the selected state aren't supposed to change their background color,
184+
// because the checkbox already indicates that they're selected. This happened to work in M2,
185+
// due to `list-item-selected-container-color` being the same as `list-item-container-color`,
186+
// but that's no longer the case in M3. This overrides ensures that the appearance is consistent.
187+
@include token-utils.use-tokens(tokens-mdc-list.$prefix, tokens-mdc-list.get-token-slots()) {
188+
$selected-token: token-utils.get-token-variable(list-item-selected-container-color);
189+
$base-token: token-utils.get-token-variable(list-item-container-color);
190+
#{$selected-token}: var(#{$base-token}, transparent);
191+
}
192+
}
193+
181194
// For options, render the focus indicator when the class .mat-mdc-option-active is present.
182195
.mat-mdc-option-active .mat-mdc-focus-indicator::before {
183196
content: '';

0 commit comments

Comments
 (0)