Skip to content

Commit 497816b

Browse files
crisbetojelbourn
authored andcommitted
fix(typography): deprecation warning if null font family is passed in (angular#9002)
* Fixes a deprecation warning that gets logged by `mat-font-family` if the consumer passes in `null` as the `font-family`. * Adds better handling if any of the typography properties are null. Fixes angular#8973.
1 parent ef06a9c commit 497816b

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/lib/core/typography/_typography-utils.scss

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
$font-family: _mat-get-type-value($config, $level, font-family);
2727
}
2828

29-
@return unquote($font-family);
29+
@return if($font-family == null, $font-family, unquote($font-family));
3030
}
3131

3232
// Converts a typography level into CSS styles.
@@ -36,8 +36,26 @@
3636
$line-height: mat-line-height($config, $level);
3737
$font-family: mat-font-family($config, $level);
3838

39-
// Use the shorthand `font` to represent a typography level, because it's the shortest. Notes that
40-
// we need to use interpolation for `font-size/line-height` in order to prevent SASS from dividing
41-
// the two values.
42-
font: $font-weight #{$font-size}/#{$line-height} $font-family;
39+
// If any of the values are set to `inherit`, we can't use the shorthand
40+
// so we fall back to passing in the individual properties.
41+
@if ($font-size == inherit or
42+
$font-weight == inherit or
43+
$line-height == inherit or
44+
$font-family == inherit or
45+
$font-size == null or
46+
$font-weight == null or
47+
$line-height == null or
48+
$font-family == null) {
49+
50+
font-size: $font-size;
51+
font-weight: $font-weight;
52+
line-height: $line-height;
53+
font-family: $font-family;
54+
}
55+
@else {
56+
// Otherwise use the shorthand `font` to represent a typography level, because it's the the
57+
// least amount of bytes. Note that we need to use interpolation for `font-size/line-height`
58+
// in order to prevent SASS from dividing the two values.
59+
font: $font-weight #{$font-size}/#{$line-height} $font-family;
60+
}
4361
}

0 commit comments

Comments
 (0)