google/material-design-lite

Text Field does not support implicit label association

Open

#1,737 创建于 2015年10月13日

在 GitHub 查看
 (4 评论) (0 反应) (0 负责人)HTML (32,173 star) (4,926 fork)batch import
Textfieldhelp wantedresearch

描述

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.

贡献者指南

Text Field does not support implicit label association · google/material-design-lite#1737 | Good First Issue