@@ -32,11 +32,11 @@ npm install @material/textfield
3232### HTML Structure
3333
3434``` html
35- <div class =" mdc-text-field" >
36- <input type = " text" id = " my- text-field " class = " mdc-text-field__input " >
37- <label class =" mdc-floating-label" for =" my-text-field " >Hint text</label >
35+ <label class =" mdc-text-field" >
36+ <input class = " mdc- text-field__input " type = " text" aria-labelledby = " my-label-id " >
37+ <span class =" mdc-floating-label" id =" my-label-id " >Hint text</span >
3838 <div class =" mdc-line-ripple" ></div >
39- </div >
39+ </label >
4040```
4141
4242> NOTE: For more details, see [ MDC Line Ripple] ( ../mdc-line-ripple/README.md )
@@ -65,12 +65,12 @@ const textField = new MDCTextField(document.querySelector('.mdc-text-field'));
6565Full width text fields are useful for in-depth tasks or entering complex information.
6666
6767``` html
68- <div class =" mdc-text-field mdc-text-field--fullwidth" >
68+ <label class =" mdc-text-field mdc-text-field--fullwidth" >
6969 <input class =" mdc-text-field__input"
7070 type =" text"
7171 placeholder =" Full-Width Text Field"
7272 aria-label =" Full-Width Text Field" >
73- </div >
73+ </label >
7474```
7575
7676> _ NOTE_ : Do not use ` mdc-text-field--outlined ` to style a full width text field.
@@ -81,31 +81,31 @@ included as part of the DOM structure of a full width text field.
8181### Textarea
8282
8383``` html
84- <div class =" mdc-text-field mdc-text-field--textarea" >
85- <textarea id = " textarea " class =" mdc-text-field__input" rows =" 8" cols =" 40" ></textarea >
84+ <label class =" mdc-text-field mdc-text-field--textarea" >
85+ <textarea class =" mdc-text-field__input" aria-labelledby = " my-label-id " rows =" 8" cols =" 40" ></textarea >
8686 <div class =" mdc-notched-outline" >
8787 <div class =" mdc-notched-outline__leading" ></div >
8888 <div class =" mdc-notched-outline__notch" >
89- <label for = " textarea " class =" mdc-floating-label" >Textarea Label</label >
89+ <label class =" mdc-floating-label" id = " my-label-id " >Textarea Label</label >
9090 </div >
9191 <div class =" mdc-notched-outline__trailing" ></div >
9292 </div >
93- </div >
93+ </label >
9494```
9595
9696### Outlined
9797
9898``` html
99- <div class =" mdc-text-field mdc-text-field--outlined" >
100- <input type =" text" id = " tf-outlined " class = " mdc-text-field__input " >
99+ <label class =" mdc-text-field mdc-text-field--outlined" >
100+ <input type =" text" class = " mdc-text-field__input " aria-labelledby = " my-label-id " >
101101 <div class =" mdc-notched-outline" >
102102 <div class =" mdc-notched-outline__leading" ></div >
103103 <div class =" mdc-notched-outline__notch" >
104- <label for = " tf-outlined " class = " mdc-floating- label" >Your Name</label >
104+ <span class = " mdc-floating-label " id = " my- label-id " >Your Name</span >
105105 </div >
106106 <div class =" mdc-notched-outline__trailing" ></div >
107107 </div >
108- </div >
108+ </label >
109109```
110110
111111See [ here] ( ../mdc-notched-outline/ ) for more information on using the notched outline sub-component.
@@ -117,11 +117,11 @@ See [here](../mdc-notched-outline/) for more information on using the notched ou
117117To disable the text field, add the ` disabled ` attribute to the ` <input> ` element and add the ` mdc-text-field--disabled ` class to the ` mdc-text-field ` element.
118118
119119``` html
120- <div class =" mdc-text-field mdc-text-field--disabled" >
121- <input type = " text" id = " disabled- text-field " class = " mdc-text-field__input " disabled >
122- <label class =" mdc-floating-label" for = " disabled-text-field " >Disabled text field</label >
120+ <label class =" mdc-text-field mdc-text-field--disabled" >
121+ <input class = " mdc- text-field__input " type = " text" aria-labelledby = " my-label-id " disabled >
122+ <span class =" mdc-floating-label" id = " my-label-id " >Disabled text field</span >
123123 <div class =" mdc-line-ripple" ></div >
124- </div >
124+ </label >
125125```
126126
127127### Text Field without label
@@ -132,34 +132,34 @@ Add class name `mdc-text-field--no-label` and remove the label element from the
132132#### Filled
133133
134134``` html
135- <div class =" mdc-text-field mdc-text-field--no-label" >
136- <input type = " text " class =" mdc-text-field__input" placeholder =" Placeholder text" aria-label =" Label" >
135+ <label class =" mdc-text-field mdc-text-field--no-label" >
136+ <input class =" mdc-text-field__input" type = " text " placeholder =" Placeholder text" aria-label =" Label" >
137137 <div class =" mdc-line-ripple" ></div >
138- </div >
138+ </label >
139139```
140140
141141#### Outlined
142142
143143``` html
144- <div class =" mdc-text-field mdc-text-field--outlined mdc-text-field--no-label" >
145- <input type = " text " class =" mdc-text-field__input" aria-label =" Label" >
144+ <label class =" mdc-text-field mdc-text-field--outlined mdc-text-field--no-label" >
145+ <input class =" mdc-text-field__input" type = " text " aria-label =" Label" >
146146 <div class =" mdc-notched-outline" >
147147 <div class =" mdc-notched-outline__leading" ></div >
148148 <div class =" mdc-notched-outline__trailing" ></div >
149149 </div >
150- </div >
150+ </label >
151151```
152152
153153#### Textarea
154154
155155``` html
156- <div class =" mdc-text-field mdc-text-field--textarea mdc-text-field--no-label" >
156+ <label class =" mdc-text-field mdc-text-field--textarea mdc-text-field--no-label" >
157157 <textarea class =" mdc-text-field__input" rows =" 8" cols =" 40" aria-label =" Label" ></textarea >
158158 <div class =" mdc-notched-outline" >
159159 <div class =" mdc-notched-outline__leading" ></div >
160160 <div class =" mdc-notched-outline__trailing" ></div >
161161 </div >
162- </div >
162+ </label >
163163```
164164
165165### Text Field with Helper Text
@@ -169,13 +169,16 @@ and disappears on input field blur by default, or it can be persistent. Helper t
169169which is immediate sibling of ` .mdc-text-field ` . See [ here] ( helper-text/ ) for more information on using helper text.
170170
171171``` html
172- <div class =" mdc-text-field" >
173- <input type =" text" id =" my-text-field" class =" mdc-text-field__input" >
174- <label class =" mdc-floating-label" for =" my-text-field" >My Label</label >
172+ <label class =" mdc-text-field" >
173+ <input class =" mdc-text-field__input" type =" text"
174+ aria-labelledby =" my-label-id"
175+ aria-controls =" my-helper-id"
176+ aria-describedby =" my-helper-id" >
177+ <span class =" mdc-floating-label" id =" my-label-id" >My Label</span >
175178 <div class =" mdc-line-ripple" ></div >
176- </div >
179+ </label >
177180<div class =" mdc-text-field-helper-line" >
178- <div class =" mdc-text-field-helper-text" >helper text</div >
181+ <div class =" mdc-text-field-helper-text" id = " my-helper-id " aria-hidden = " true " >helper text</div >
179182</div >
180183```
181184
@@ -186,11 +189,11 @@ Character counter should be rendered inside `.mdc-text-field-helper-line` elemen
186189See [ here] ( character-counter/ ) for more information on using character counter.
187190
188191``` html
189- <div class =" mdc-text-field" >
190- <input type = " text" id = " my- text-field " class = " mdc-text-field__input " maxlength =" 10" >
191- <label class =" mdc-floating-label" for =" my-text-field " >My Label</label >
192+ <label class =" mdc-text-field" >
193+ <input class = " mdc- text-field__input " type = " text" aria-labelledby = " my-label-id " maxlength =" 10" >
194+ <span class =" mdc-floating-label" id =" my-label-id " >My Label</span >
192195 <div class =" mdc-line-ripple" ></div >
193- </div >
196+ </label >
194197<div class =" mdc-text-field-helper-line" >
195198 <div class =" mdc-text-field-character-counter" >0 / 10</div >
196199</div >
@@ -202,17 +205,17 @@ The layout structure of character counter for multi-line text field (textarea) i
202205inside of text field component.
203206
204207``` html
205- <div class =" mdc-text-field mdc-text-field--textarea" >
208+ <label class =" mdc-text-field mdc-text-field--textarea" >
206209 <div class =" mdc-text-field-character-counter" >0 / 140</div >
207- <textarea id = " textarea " class =" mdc-text-field__input" rows =" 8" cols =" 40" maxlength =" 140" ></textarea >
210+ <textarea class =" mdc-text-field__input" aria-labelledby = " my-label-id " rows =" 8" cols =" 40" maxlength =" 140" ></textarea >
208211 <div class =" mdc-notched-outline" >
209212 <div class =" mdc-notched-outline__leading" ></div >
210213 <div class =" mdc-notched-outline__notch" >
211- <label for = " textarea " class =" mdc-floating-label" >Textarea Label</label >
214+ <span class =" mdc-floating-label" id = " my-label-id " >Textarea Label</span >
212215 </div >
213216 <div class =" mdc-notched-outline__trailing" ></div >
214217 </div >
215- </div >
218+ </label >
216219```
217220
218221Helper text and Character counter are optional subcomponents of text field that can co-exist independently.
@@ -229,11 +232,11 @@ well as interaction targets. See [here](icon/) for more information on using ico
229232by HTML5's form validation API.
230233
231234``` html
232- <div class =" mdc-text-field" >
233- <input type = " password " id = " pw " class = " mdc-text-field__input " required minlength =8 >
234- <label for = " pw " class =" mdc-floating-label" >Password</label >
235+ <label class =" mdc-text-field" >
236+ <input class = " mdc-text-field__input " type = " password " aria-labelledby = " my-label-id " required minlength =" 8 " >
237+ <span class =" mdc-floating-label" id = " my-label-id " >Password</span >
235238 <div class =" mdc-line-ripple" ></div >
236- </div >
239+ </label >
237240```
238241
239242` MDCTextFieldFoundation ` automatically appends an asterisk to the label text if the required attribute is set.
@@ -246,13 +249,13 @@ ensure that the label moves out of the way of the text field's value and prevent
246249Un-styled Content (** FOUC** ).
247250
248251``` html
249- <div class =" mdc-text-field" >
250- <input type = " text" id = " pre-filled " class = " mdc-text-field__input " value =" Pre-filled value" >
251- <label class =" mdc-floating-label mdc-floating-label--float-above" for = " pre-filled " >
252+ <label class =" mdc-text-field" >
253+ <input class = " mdc- text-field__input " type = " text " aria-labelledby = " my-label-id " value =" Pre-filled value" >
254+ <span class =" mdc-floating-label mdc-floating-label--float-above" id = " my-label-id " >
252255 Label in correct place
253- </label >
256+ </span >
254257 <div class =" mdc-line-ripple" ></div >
255- </div >
258+ </label >
256259```
257260
258261## Style Customization
0 commit comments