Skip to content

Commit 60d6bd6

Browse files
devversionandrewseguin
authored andcommitted
fix(material-experimental/mdc-form-field): prevent label from jumping in outline notch
1 parent 7fe8381 commit 60d6bd6

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/material-experimental/mdc-form-field/_mdc-text-field-structure-overrides.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,21 @@
114114
.mat-mdc-text-field-wrapper.mdc-text-field--outlined .mdc-text-field__input {
115115
display: inline-block;
116116
}
117+
118+
// By default, MDC aligns the label using percentage. This will be overwritten based
119+
// on whether a textarea is used. This is not possible in our implementation of the
120+
// form-field because we do not know what type of form-field control is set up. Hence
121+
// we always use a fixed position for the label. This does not have any implications.
122+
.mat-mdc-text-field-wrapper .mdc-floating-label {
123+
top: $mat-form-field-baseline;
124+
}
125+
126+
// As mentioned in the override before, MDC aligns the label using percentage. This means that
127+
// MDC tries to offset the label when the parent element changes in the notched-outline. For
128+
// example, the outline stroke width changes on focus. Since we updated the label to use a fixed
129+
// position, we don't need the vertical offsetting (that will shift the label incorrectly now).
130+
// Note: Increased specificity needed here since MDC overwrites the padding on `:focus`.
131+
.mat-mdc-form-field .mat-mdc-text-field-wrapper.mdc-text-field .mdc-notched-outline__notch {
132+
padding-top: 0;
133+
}
117134
}

src/material-experimental/mdc-form-field/_mdc-text-field-textarea-overrides.scss

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,4 @@
3030
// This brings it in line with other browsers.
3131
overflow: auto;
3232
}
33-
34-
// By default, MDC aligns the label using percentage. This will be overwritten based
35-
// on whether a textarea is used. This is not possible in our implementation of the
36-
// form-field because we do not know what type of form-field control is set up. Hence
37-
// we always use a fixed position for the label. This does not have any implications.
38-
.mat-mdc-text-field-wrapper .mdc-floating-label {
39-
top: $mat-form-field-baseline;
40-
}
4133
}

0 commit comments

Comments
 (0)