Skip to content

Commit 9ac5d13

Browse files
mmalerbatinayuangao
authored andcommitted
fix(input): fix input/placeholder alignment on safari (#6072)
1 parent d9e6f75 commit 9ac5d13

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/lib/input/_input-theme.scss

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@
143143
// we need to divide by the scale factor to make it half of the original text size. We again need
144144
// to subtract off the line spacing since the mocks measure to the edge of the text, not the edge
145145
// of the line.
146-
$subscript-margin-top: 0.5em / $subscript-font-scale - $line-spacing;
146+
$subscript-margin-top: 0.5em / $subscript-font-scale - ($line-spacing * 2);
147147
// The padding applied to the input-wrapper to reserve space for the subscript, since it's
148148
// absolutely positioned. This is a combination of the subscript's margin and line-height, but we
149149
// need to multiply by the subscript font scale factor since the wrapper has a larger font size.
150-
$wrapper-padding-bottom: 0.5em + ($line-height * $subscript-font-scale);
150+
$wrapper-padding-bottom: ($subscript-margin-top + $line-height) * $subscript-font-scale;
151151

152152
.mat-input-container {
153153
font-family: mat-font-family($config);
@@ -193,6 +193,12 @@
193193
}
194194
}
195195

196+
// <input> elements seem to have their height set slightly too large on Safari causing the text to
197+
// be misaligned w.r.t. the placeholder. Adding this margin corrects it.
198+
input.mat-input-element {
199+
margin-top: -$line-spacing * 1em;
200+
}
201+
196202
.mat-input-placeholder-wrapper {
197203
top: -$infix-margin-top;
198204
padding-top: $infix-margin-top;

src/lib/input/input-container.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ $mat-input-underline-height: 1px !default;
7777
border: none;
7878
outline: none;
7979
padding: 0;
80+
margin: 0;
8081
width: 100%;
8182

8283
// Prevent textareas from being resized outside the container.

0 commit comments

Comments
 (0)