google/material-design-lite

Text Field does not support implicit label association

Open

#1737 aperta il 13 ott 2015

Vedi su GitHub
 (4 commenti) (0 reazioni) (0 assegnatari)HTML (4926 fork)batch import
Textfieldhelp wantedresearch

Metriche repository

Star
 (32.173 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

The HTML spec allows for an implicit association between a label and an input by making the input a descendant of the label. This avoids the need for an associating for attribute, which can be problematic when generating dynamic markup because element identifiers must be unique across the entire page. Using an implicit association avoids the need for id or for attributes altogether. You can work around this by generating a unique identifier when generating the markup - but that's a little inconvenient.

So instead of:

<div class="mdl-textfield mdl-js-textfield">
  <input class="mdl-textfield__input" type="text" id="sample1" />
  <label class="mdl-textfield__label" for="sample1">Text...</label>
</div>

It would be convenient to be able to do this:

<div class="mdl-textfield mdl-js-textfield">
  <label class="mdl-textfield__label"><input class="mdl-textfield__input" type="text" /> Text...</label>
</div>

http://www.w3.org/TR/html5/forms.html#the-label-element

The MDL textfield does not appear to support this arrangement.

Guida contributor