Skip to content

Commit cc0532b

Browse files
authored
fix(material/badge): content incorrectly truncated in M3 (#29854)
Fixes that at some point the M3 badge regressed to where the content was always being truncated. The regression was likely, because the previous setup was very fragile and it was relying on some tokens never being emitted. These changes remove the need to rely on fallbacks and resolve the issue by setting the correct token values. Fixes #29788.
1 parent 1e56632 commit cc0532b

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

src/material/badge/badge.scss

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ $large-size: $default-size + 6;
2222
// * `container-size` token - In M2 the token is emitted as `unset` to preserve the legacy
2323
// behavior while in M3 it targets `min-width` and `min-height` which allows the badge to
2424
// grow with the content.
25-
width: token-utils.get-token-variable($legacy-size-var-name, $fallback: unset);
26-
height: token-utils.get-token-variable($legacy-size-var-name, $fallback: unset);
27-
min-width: token-utils.get-token-variable($size-var-name, $fallback: unset);
28-
min-height: token-utils.get-token-variable($size-var-name, $fallback: unset);
29-
line-height: token-utils.get-token-variable($legacy-size-var-name);
25+
@include token-utils.create-token-slot(width, $legacy-size-var-name);
26+
@include token-utils.create-token-slot(height, $legacy-size-var-name);
27+
@include token-utils.create-token-slot(min-width, $size-var-name);
28+
@include token-utils.create-token-slot(min-height, $size-var-name);
29+
@include token-utils.create-token-slot(line-height, '#{$prefix}line-height');
3030
@include token-utils.create-token-slot(padding, '#{$prefix}container-padding');
3131
@include token-utils.create-token-slot(font-size, '#{$prefix}text-size');
3232
@include token-utils.create-token-slot(margin, '#{$prefix}container-offset');

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@
66
@use '../../../theming/inspection';
77
@use '../../../style/sass-utils';
88

9+
$_default-size: 22px;
10+
$_small-size: $_default-size - 6px;
11+
$_large-size: $_default-size + 6px;
12+
913
// The prefix used to generate the fully qualified name for tokens in this file.
1014
$prefix: (mat, badge);
1115

1216
// Tokens that can't be configured through Angular Material's current theming API,
1317
// but may be in a future version of the theming API.
1418
@function get-unthemable-tokens() {
15-
$default-size: 22px;
16-
$small-size: $default-size - 6;
17-
$large-size: $default-size + 6;
19+
$default-size: $_default-size;
20+
$small-size: $_small-size;
21+
$large-size: $_large-size;
1822

1923
@return (
2024
container-shape: 50%,
@@ -77,10 +81,15 @@ $prefix: (mat, badge);
7781

7882
@return (
7983
text-font: inspection.get-theme-typography($theme, body-2, font-family),
84+
line-height: $_default-size,
8085
text-size: $base-size,
8186
text-weight: 600,
87+
8288
small-size-text-size: $base-size * 0.75,
89+
small-size-line-height: $_small-size,
90+
8391
large-size-text-size: $base-size * 2,
92+
large-size-line-height: $_large-size,
8493
);
8594
}
8695

src/material/core/tokens/m3/mat/_badge.scss

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ $prefix: (mat, badge);
2525
small-size-text-size: token-definition.hardcode(0, $exclude-hardcoded),
2626
container-shape: map.get($systems, md-sys-shape, corner-full),
2727
container-size: token-definition.hardcode(16px, $exclude-hardcoded),
28-
legacy-container-size: token-definition.hardcode(16px, $exclude-hardcoded),
29-
legacy-small-size-container-size: token-definition.hardcode(16px, $exclude-hardcoded),
28+
line-height: token-definition.hardcode(16px, $exclude-hardcoded),
29+
legacy-container-size: token-definition.hardcode(unset, $exclude-hardcoded),
30+
legacy-small-size-container-size: token-definition.hardcode(unset, $exclude-hardcoded),
3031
small-size-container-size: token-definition.hardcode(6px, $exclude-hardcoded),
32+
small-size-line-height: token-definition.hardcode(6px, $exclude-hardcoded),
3133
container-padding: token-definition.hardcode(0 4px, $exclude-hardcoded),
3234
small-size-container-padding: token-definition.hardcode(0, $exclude-hardcoded),
3335
container-offset: token-definition.hardcode(-12px 0, $exclude-hardcoded),
@@ -37,11 +39,12 @@ $prefix: (mat, badge);
3739

3840
// This size isn't in the M3 spec so we emit the same values as for `medium`.
3941
large-size-container-size: token-definition.hardcode(16px, $exclude-hardcoded),
42+
large-size-line-height: token-definition.hardcode(16px, $exclude-hardcoded),
4043
large-size-container-offset: token-definition.hardcode(-12px 0, $exclude-hardcoded),
4144
large-size-container-overlap-offset: token-definition.hardcode(-12px, $exclude-hardcoded),
4245
large-size-text-size: map.get($systems, md-sys-typescale, label-small-size),
4346
large-size-container-padding: token-definition.hardcode(0 4px, $exclude-hardcoded),
44-
legacy-large-size-container-size: token-definition.hardcode(16px, $exclude-hardcoded),
47+
legacy-large-size-container-size: token-definition.hardcode(unset, $exclude-hardcoded),
4548
), (
4649
primary: (
4750
background-color: map.get($systems, md-sys-color, primary),

0 commit comments

Comments
 (0)