Skip to content

Commit 8dcdad2

Browse files
committed
fix(material/form-field): inconsistent height for non-text inputs
Fixes that some non-text input variants were taller than the text ones. Fixes #26915.
1 parent 23f9563 commit 8dcdad2

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
// Reduce the size of the native buttons in a date/time input,
16+
// because they can increase the height of the input (see #13317).
17+
&::-webkit-inner-spin-button,
18+
&::-webkit-calendar-picker-indicator,
19+
&::-webkit-clear-button {
20+
font-size: 0.75em;
21+
}
22+
23+
// Native datetime inputs have an element in the shadow DOM that makes them taller than
24+
// other inputs. These changes reset the user agent styles to make them consistent.
25+
// via https://8yd.no/article/date-input-height-in-safari
26+
&::-webkit-datetime-edit {
27+
line-height: 1;
28+
padding: 0;
29+
margin-bottom: -2px;
30+
}
31+
}
32+
}

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)