Skip to content

fix(material/form-field): inconsistent height for non-text inputs #26941

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

Merged
merged 1 commit into from
Apr 19, 2023
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
1 change: 1 addition & 0 deletions src/material/form-field/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ sass_library(
"_form-field-subscript.scss",
"_mdc-text-field-structure-overrides.scss",
"_mdc-text-field-textarea-overrides.scss",
"_user-agent-overrides.scss",
],
deps = [
"//:mdc_sass_lib",
Expand Down
24 changes: 24 additions & 0 deletions src/material/form-field/_user-agent-overrides.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Mixin that resets user agent styles to make the form field behave consistently.
@mixin private-form-field-user-agent-overrides() {
.mat-mdc-form-field-input-control {
// Due to the native input masking these inputs can be slightly taller than
// the plain text inputs. We normalize it by resetting the line height.
&[type='date'],
&[type='datetime'],
&[type='datetime-local'],
&[type='month'],
&[type='week'],
&[type='time'] {
line-height: 1;
}

// Native datetime inputs have an element in the shadow DOM that makes them taller than
// other inputs. These changes reset the user agent styles to make them consistent.
// via https://8yd.no/article/date-input-height-in-safari
&::-webkit-datetime-edit {
line-height: 1;
padding: 0;
margin-bottom: -2px;
}
}
}
2 changes: 2 additions & 0 deletions src/material/form-field/form-field.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@use './form-field-focus-overlay';
@use './form-field-high-contrast';
@use './form-field-native-select';
@use './user-agent-overrides';
@use './mdc-text-field-textarea-overrides';
@use './mdc-text-field-structure-overrides';

Expand All @@ -33,6 +34,7 @@
@include form-field-focus-overlay.private-form-field-focus-overlay();
@include form-field-native-select.private-form-field-native-select();
@include form-field-high-contrast.private-form-field-high-contrast();
@include user-agent-overrides.private-form-field-user-agent-overrides();

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