Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit e34b251

Browse files
fix(text-field): Update to match spec (#3397)
BREAKING CHANGE: This PR removes the margin-top from the mdc-text-field container. This can cause a UI to shift/change.
1 parent 9882c7d commit e34b251

File tree

8 files changed

+202
-199
lines changed

8 files changed

+202
-199
lines changed

demos/text-field.html

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,7 @@ <h2>Full Functionality JS Component (Floating Label, Validation)</h2>
8686
<div class="mdc-line-ripple"></div>
8787
</div>
8888
<p id="my-text-field-helper-text" class="mdc-text-field-helper-text"
89-
aria-hidden="true" style="visibility: hidden">
90-
Helper Text
91-
</p>
89+
aria-hidden="true" style="visibility: hidden">Helper Text</p>
9290
</section>
9391
<div>
9492
<input id="disable" type="checkbox">
@@ -137,9 +135,7 @@ <h2>Password field with validation</h2>
137135
<div class="mdc-line-ripple"></div>
138136
</div>
139137
<p class="mdc-text-field-helper-text mdc-text-field-helper-text--persistent mdc-text-field-helper-text--validation-msg"
140-
id="pw-validation-msg">
141-
Must be at least 8 characters long
142-
</p>
138+
id="pw-validation-msg">Must be at least 8 characters long</p>
143139
</section>
144140

145141
<section class="example">
@@ -158,9 +154,7 @@ <h2>Outlined Text Field</h2>
158154
<div class="mdc-notched-outline__idle"></div>
159155
</div>
160156
<p class="mdc-text-field-helper-text mdc-text-field-helper-text--validation-msg"
161-
id="name-validation-message">
162-
Helper Text
163-
</p>
157+
id="name-validation-message">Helper Text</p>
164158
</div>
165159
<div>
166160
<input id="outlined-disable" type="checkbox">
@@ -194,7 +188,7 @@ <h2>Outlined Text Field</h2>
194188

195189
<section class="example" id="demo-tf-icon-container">
196190
<h2>Text Field - Leading/Trailing icons</h2>
197-
<div id="demo-tf-leading-wrapper">
191+
<div id="demo-tf-leading-wrapper" class="demo-tf-add-space">
198192
<div id="tf-leading-example"
199193
class="mdc-text-field mdc-text-field--with-leading-icon" data-demo-no-auto-js>
200194
<i class="material-icons mdc-text-field__icon" tabindex="0" role="button">event</i>
@@ -203,7 +197,7 @@ <h2>Text Field - Leading/Trailing icons</h2>
203197
<div class="mdc-line-ripple"></div>
204198
</div>
205199
</div>
206-
<div id="demo-tf-trailing-wrapper">
200+
<div id="demo-tf-trailing-wrapper" class="demo-tf-add-space">
207201
<div id="tf-trailing-example"
208202
class="mdc-text-field mdc-text-field--with-trailing-icon" data-demo-no-auto-js>
209203
<input type="text" id="tf-trailing" class="mdc-text-field__input">
@@ -212,7 +206,7 @@ <h2>Text Field - Leading/Trailing icons</h2>
212206
<div class="mdc-line-ripple"></div>
213207
</div>
214208
</div>
215-
<div id="demo-tf-outlined-leading-wrapper">
209+
<div id="demo-tf-outlined-leading-wrapper" class="demo-tf-add-space">
216210
<div id="tf-outlined-leading-example"
217211
class="mdc-text-field mdc-text-field--outlined mdc-text-field--with-leading-icon" data-demo-no-auto-js>
218212
<i class="material-icons mdc-text-field__icon" tabindex="0" role="button">event</i>
@@ -226,7 +220,7 @@ <h2>Text Field - Leading/Trailing icons</h2>
226220
<div class="mdc-notched-outline__idle"></div>
227221
</div>
228222
</div>
229-
<div id="demo-tf-outlined-trailing-wrapper" class="demo-text-field-wrapper">
223+
<div id="demo-tf-outlined-trailing-wrapper" class="demo-text-field-wrapper demo-tf-add-space">
230224
<div id="tf-outlined-trailing-example"
231225
class="mdc-text-field mdc-text-field--outlined mdc-text-field--with-trailing-icon" data-demo-no-auto-js>
232226
<input type="text" id="tf-outlined-trailing" class="mdc-text-field__input">
@@ -346,8 +340,7 @@ <h2>Custom error state behaviour - remove error state as soon as invalid input i
346340
<div class="mdc-line-ripple"></div>
347341
</div>
348342
<p id="username-helper-text" class="mdc-text-field-helper-text mdc-text-field-helper-text--persistent mdc-text-field-helper-text--validation-msg" aria-hidden="true"
349-
>Enter 10 digit phone number including area code
350-
</p>
343+
>Enter 10 digit phone number including area code</p>
351344
</section>
352345
</section>
353346
</main>

demos/text-field.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,6 @@
129129
margin-bottom: 8px;
130130
}
131131

132+
.demo-tf-add-space {
133+
margin: 10px 0;
134+
}

packages/mdc-notched-outline/foundation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class MDCNotchedOutlineFoundation extends MDCFoundation {
9898
const width = this.adapter_.getWidth();
9999
const height = this.adapter_.getHeight();
100100
const cornerWidth = radius + 1.2;
101-
const leadingStrokeLength = Math.abs(11 - cornerWidth);
101+
const leadingStrokeLength = Math.abs(12 - cornerWidth);
102102
const paddedNotchWidth = notchWidth + 8;
103103

104104
// The right, bottom, and left sides of the outline follow the same SVG path.

packages/mdc-notched-outline/mdc-notched-outline.scss

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,17 @@
2828

2929
// Notched Outline is intended for use by multiple components, but its styles should only be emitted once when bundled
3030
@include mdc-base-emit-once("mdc-notched-outline") {
31-
.mdc-notched-outline {
31+
.mdc-notched-outline,
32+
.mdc-notched-outline__idle {
3233
position: absolute;
3334
top: 0;
3435
left: 0;
35-
width: calc(100% - 1px);
36-
height: calc(100% - 2px);
36+
box-sizing: border-box;
37+
width: 100%;
38+
height: 100%;
39+
}
40+
41+
.mdc-notched-outline {
3742
transition: opacity $mdc-notched-outline-transition-duration $mdc-animation-standard-curve-timing-function;
3843
opacity: 0;
3944
text-align: left;
@@ -53,11 +58,6 @@
5358
}
5459

5560
.mdc-notched-outline__idle {
56-
position: absolute;
57-
top: 0;
58-
left: 0;
59-
width: calc(100% - 4px);
60-
height: calc(100% - 4px);
6161
transition:
6262
opacity $mdc-notched-outline-transition-duration $mdc-animation-standard-curve-timing-function,
6363
border-color $mdc-notched-outline-transition-duration $mdc-animation-standard-curve-timing-function;

packages/mdc-textfield/_mixins.scss

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,6 @@
190190
@include mdc-floating-label-float-position($mdc-text-field-dense-label-position-y, 0%, $mdc-text-field-dense-label-scale);
191191
@include mdc-floating-label-shake-animation(text-field-dense);
192192

193-
margin-top: 12px;
194-
margin-bottom: 4px;
195-
196193
.mdc-text-field__input {
197194
padding: 12px 12px 0;
198195
}
@@ -293,7 +290,7 @@
293290

294291
.mdc-text-field__input {
295292
display: flex;
296-
padding: 12px;
293+
padding: 12px 16px 14px;
297294
border: none !important; // FF adds unwanted border in HC mode on windows.
298295
background-color: transparent;
299296
z-index: 1;
@@ -304,6 +301,8 @@
304301
}
305302

306303
.mdc-floating-label {
304+
@include mdc-rtl-reflexive-position(left, 16px);
305+
307306
width: auto;
308307
}
309308
}
@@ -371,15 +370,19 @@
371370
}
372371

373372
@mixin mdc-text-field-with-trailing-icon_ {
374-
@include mdc-text-field-icon-horizontal-position_(right, $mdc-text-field-icon-position, $mdc-text-field-icon-padding);
373+
@include mdc-text-field-icon-horizontal-position_(right, $mdc-text-field-trailing-icon-position, $mdc-text-field-icon-padding);
374+
375+
// Outlined uses 16px for text alignment when using a trailing icon.
376+
&.mdc-text-field--outlined {
377+
@include mdc-text-field-icon-horizontal-position_(right, $mdc-text-field-icon-position, $mdc-text-field-icon-padding);
378+
}
375379
}
376380

377381
@mixin mdc-text-field-dense-with-trailing-icon_ {
378382
@include mdc-text-field-icon-horizontal-position_(right, $mdc-text-field-dense-icon-position, $mdc-text-field-dense-icon-padding);
379383
}
380384

381385
// Full Width
382-
383386
@mixin mdc-text-field-fullwidth_ {
384387
width: 100%;
385388

@@ -400,7 +403,6 @@
400403
}
401404

402405
// Textarea
403-
404406
@mixin mdc-text-field-textarea-disabled_ {
405407
@include mdc-text-field-textarea-stroke-color_($mdc-textarea-disabled-border-color);
406408
@include mdc-text-field-textarea-fill-color_($mdc-textarea-disabled-background);

packages/mdc-textfield/icon/_variables.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
// THE SOFTWARE.
2121
//
2222

23-
$mdc-text-field-icon-position: 15px;
23+
$mdc-text-field-icon-position: 16px;
24+
$mdc-text-field-trailing-icon-position: 12px;
2425
$mdc-text-field-icon-padding: 48px;
2526
$mdc-text-field-dense-icon-position: 12px;
2627
$mdc-text-field-dense-icon-padding: 38px;

packages/mdc-textfield/mdc-text-field.scss

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,15 @@
7272
position: relative;
7373
box-sizing: border-box;
7474
height: 56px;
75-
margin-top: 16px;
7675
overflow: hidden;
7776
will-change: opacity, transform, color;
77+
78+
// stylelint-disable-next-line plugin/selector-bem-pattern
79+
.mdc-floating-label {
80+
@include mdc-rtl-reflexive-position(left, 12px);
81+
82+
pointer-events: none;
83+
}
7884
}
7985

8086
.mdc-text-field__input {
@@ -84,7 +90,7 @@
8490
box-sizing: border-box;
8591
width: 100%;
8692
height: 100%;
87-
padding: 20px 16px 0;
93+
padding: 20px 12px 6px;
8894
transition: mdc-text-field-transition(opacity);
8995
border: none;
9096
border-bottom: 1px solid;
@@ -106,20 +112,13 @@
106112
box-shadow: none;
107113
}
108114
}
109-
110-
// stylelint-disable plugin/selector-bem-pattern
111-
.mdc-floating-label {
112-
pointer-events: none;
113-
}
114-
115-
// Move label when text-field gets autofilled in Chrome
115+
// stylelint-disable-next-line plugin/selector-bem-pattern
116+
// Move label when text-field gets auto-filled in Chrome.
116117
.mdc-text-field__input:-webkit-autofill + .mdc-floating-label {
117118
transform: translateY(-50%) scale(.75);
118119
cursor: auto;
119120
}
120121

121-
// stylelint-enable plugin/selector-bem-pattern
122-
123122
.mdc-text-field--outlined {
124123
@include mdc-text-field-outlined_;
125124
}
@@ -198,6 +197,11 @@
198197
}
199198

200199
.mdc-text-field + & {
200+
margin-right: 12px;
201+
margin-left: 12px;
202+
}
203+
204+
.mdc-text-field--outlined + & {
201205
margin-right: 16px;
202206
margin-left: 16px;
203207
}

0 commit comments

Comments
 (0)