Skip to content

Commit 5623a8c

Browse files
committed
fix(material/form-field): inconsistent height for non-text inputs (#26941)
Fixes that some non-text input variants were taller than the text ones. Fixes #26915. (cherry picked from commit 298cbaf)
1 parent af293a1 commit 5623a8c

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/material/form-field/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ sass_library(
6262
"_form-field-subscript.scss",
6363
"_mdc-text-field-structure-overrides.scss",
6464
"_mdc-text-field-textarea-overrides.scss",
65+
"_user-agent-overrides.scss",
6566
],
6667
deps = [
6768
"//:mdc_sass_lib",
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Mixin that resets user agent styles to make the form field behave consistently.
2+
@mixin private-form-field-user-agent-overrides() {
3+
.mat-mdc-form-field-input-control {
4+
// Due to the native input masking these inputs can be slightly taller than
5+
// the plain text inputs. We normalize it by resetting the line height.
6+
&[type='date'],
7+
&[type='datetime'],
8+
&[type='datetime-local'],
9+
&[type='month'],
10+
&[type='week'],
11+
&[type='time'] {
12+
line-height: 1;
13+
}
14+
15+
// Native datetime inputs have an element in the shadow DOM that makes them taller than
16+
// other inputs. These changes reset the user agent styles to make them consistent.
17+
// via https://8yd.no/article/date-input-height-in-safari
18+
&::-webkit-datetime-edit {
19+
line-height: 1;
20+
padding: 0;
21+
margin-bottom: -2px;
22+
}
23+
}
24+
}

src/material/form-field/form-field.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
@use './form-field-focus-overlay';
1010
@use './form-field-high-contrast';
1111
@use './form-field-native-select';
12+
@use './user-agent-overrides';
1213
@use './mdc-text-field-textarea-overrides';
1314
@use './mdc-text-field-structure-overrides';
1415

@@ -33,6 +34,7 @@
3334
@include form-field-focus-overlay.private-form-field-focus-overlay();
3435
@include form-field-native-select.private-form-field-native-select();
3536
@include form-field-high-contrast.private-form-field-high-contrast();
37+
@include user-agent-overrides.private-form-field-user-agent-overrides();
3638

3739
// Host element of the form-field. It contains the mdc-text-field wrapper
3840
// and the subscript wrapper.

0 commit comments

Comments
 (0)