简体   繁体   English

辅助功能:我可以在 label 及其相关输入之间添加内容吗?

[英]Accessibility: Can I add content between a label and its associated input?

I have a <label> associated with an <input> (for="inputID").我有一个与<input> (for="inputID") 关联的<label>

Would I have an accessibility problem if, for example, I added a link between <label> and <input> ?例如,如果我在<label><input>之间添加了一个链接,我会遇到可访问性问题吗?

Example:例子:

 <div class="c-input"> <label for="input-1">Label</label> <a href="#">Link</a> <input id="input-1" type="text" placeholder="Placeholder"> </div>

Thanks.谢谢。

It's not a technical WCAG (accessibility) failure.这不是技术 WCAG(可访问性)故障。 You have the label associated with the <input> by using the for attribute.您使用for属性将 label 与<input>相关联。 This allows the label to be announced when a screen reader user tabs to the input field, so that's great.这允许在屏幕阅读器用户切换到输入字段时宣布label ,这太棒了。 It also allows mouse user to click on the label text and have the focus automatically move to the input field.它还允许鼠标用户单击 label 文本并将焦点自动移动到输入字段。

However, it's a little odd to have a link between the two.但是,将两者联系起来有点奇怪。 A similar layout is somewhat common for checkboxes (not input fields), especially with "agree to terms and conditions" type of checkboxes.类似的布局对于复选框(不是输入字段)来说有些常见,尤其是“同意条款和条件”类型的复选框。 The "terms" is often a link contained within the label whereas in your example, the link is outside the label. “条款”通常是 label 中包含链接,而在您的示例中,该链接位于 label 之外。

<input type="checkbox" id="mycheck">
<label for="mycheck">Agree to <a href="terms.html">terms and conditions</a></label>

Similar to your example, a screen reader user will hear the label when they tab to the checkbox ( "agree to terms and conditions, checkbox, unchecked" ).与您的示例类似,屏幕阅读器用户在选中复选框时会听到label“同意条款和条件,复选框,未选中” )。 If they tab again, they'll hear "terms and conditions, link" .如果他们再次点击,他们会听到“条款和条件,链接” If they click on the non-link part of the label, the checkbox will toggle.如果他们单击 label 的非链接部分,复选框将切换。 If they click on the link part of the label, the link will navigate to the "terms" page and the checkbox will not toggle.如果他们单击 label 的链接部分,该链接将导航到“条款”页面,并且复选框不会切换。 It's a little funky but doesn't fail WCAG.这有点时髦,但不会让 WCAG 失败。

So back to your example, should the link be part of the label or should it be outside the label?所以回到你的例子,链接应该是 label 的一部分还是应该在 label 之外? Either way it's not an accessibility failure.无论哪种方式,它都不是可访问性故障。 You have to decide which behavior you want.你必须决定你想要哪种行为。 If you need the link to be announced as part of the input field's label then the link should be embedded in the label (a child element of the <label> ).如果您需要将链接宣布为输入字段 label 的一部分,则该链接应嵌入到 label( <label>的子元素)中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM