Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(material/form-field): safely coerce line-height to em #23215

Merged
merged 1 commit into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/material/core/typography/_typography-utils.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@use 'sass:list';
@use 'sass:map';
@use 'sass:math';
@use 'sass:meta';
@use 'sass:string';
@use '../style/private';
Expand Down Expand Up @@ -96,3 +97,9 @@
@include font-shorthand($font-size, $font-weight, $line-height, $font-family);
letter-spacing: letter-spacing($config, $level);
}

/// Coerce a value to `em` if it is a unitless number, otherwise returns
/// the value provided.
@function private-coerce-unitless-to-em($value) {
@return if(math.is-unitless($value), 1em * $value, $value);
}
3 changes: 2 additions & 1 deletion src/material/form-field/_form-field-fill-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ $fill-dedupe: 0;
// The padding below the infix.
$infix-padding-bottom: 0.75em;
// The margin applied to the form-field-infix to reserve space for the floating label.
$infix-margin-top: 1em * $line-height * $subscript-font-scale;
$infix-margin-top:
$subscript-font-scale * typography-utils.private-coerce-unitless-to-em($line-height);
// The amount we offset the label from the input text in the fill appearance.
$fill-appearance-label-offset: -0.5em;

Expand Down
4 changes: 3 additions & 1 deletion src/material/form-field/_form-field-legacy-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ $legacy-dedupe: 0;
// of the text itself, not the edge of the line; therefore we subtract off the line spacing.
$infix-padding: 0.5em - $line-spacing;
// The margin applied to the form-field-infix to reserve space for the floating label.
$infix-margin-top: 1em * $line-height * $subscript-font-scale;
// If the line-height is given as a unitless number, coerce it to `em`.
$infix-margin-top:
$subscript-font-scale * typography-utils.private-coerce-unitless-to-em($line-height);
// The space between the bottom of the .mat-form-field-flex area and the subscript wrapper.
// Mocks show half of the text size, but this margin is applied to an element with the subscript
// text font size, so we need to divide by the scale factor to make it half of the original text
Expand Down
3 changes: 2 additions & 1 deletion src/material/form-field/_form-field-outline-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ $outline-dedupe: 0;
// The padding above and below the infix.
$infix-padding: 1em;
// The margin applied to the form-field-infix to reserve space for the floating label.
$infix-margin-top: 1em * $line-height * $subscript-font-scale;
$infix-margin-top:
$subscript-font-scale * typography-utils.private-coerce-unitless-to-em($line-height);
// The space between the bottom of the .mat-form-field-flex area and the subscript wrapper.
// Mocks show half of the text size, but this margin is applied to an element with the subscript
// text font size, so we need to divide by the scale factor to make it half of the original text
Expand Down
6 changes: 4 additions & 2 deletions src/material/form-field/_form-field-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ $dedupe: 0;
// The padding on the infix. Mocks show half of the text size.
$infix-padding: 0.5em;
// The margin applied to the form-field-infix to reserve space for the floating label.
$infix-margin-top: 1em * $line-height * $subscript-font-scale;
// If the line-height is given as a unitless number, coerce it to `em`.
$infix-margin-top: $subscript-font-scale *
typography-utils.private-coerce-unitless-to-em($line-height);
// Font size to use for the label and subscript text.
$subscript-font-size: $subscript-font-scale * 100%;
// Font size to use for the for the prefix and suffix icons.
Expand Down Expand Up @@ -183,7 +185,7 @@ $dedupe: 0;
width: $prefix-suffix-icon-font-scale * 1em;

.mat-icon {
height: $line-height * 1em;
height: typography-utils.private-coerce-unitless-to-em($line-height);
line-height: $line-height;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/material/input/_input-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
// <input> elements seem to have their height set slightly too large on Safari causing the text to
// be misaligned w.r.t. the placeholder. Adding this margin corrects it.
input.mat-input-element {
margin-top: -$line-spacing * 1em;
margin-top: typography-utils.private-coerce-unitless-to-em(-$line-spacing);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/material/select/_select-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
}

.mat-select-trigger {
height: $line-height * 1em;
height: typography-utils.private-coerce-unitless-to-em($line-height);
}
}

Expand Down