简体   繁体   English

如何将 aria-invalid 和 aria-describedby 属性用于复选框组

[英]How to use aria-invalid and aria-describedby attributes for checkboxe group

I have a checkbox set as a form element and need to use aria-invalid and aria-describedby attributes on them.我有一个复选框设置为表单元素,需要对它们使用 aria-invalid 和 aria-describedby 属性。 Should the attribute be written on every single checkbox or on a fieldset?属性应该写在每个复选框上还是字段集上?

In general, any object that is in error should have aria-invalid set to true.通常,任何出错的对象都应该将 aria-invalid 设置为 true。 Setting that on the fieldset might be a bit confusing.在字段集上设置它可能有点混乱。 Does it mean all the objects in the fieldset are in error?这是否意味着字段集中的所有对象都出错了? What if some are in error and others are not?如果一些错误而另一些没有错误怎么办? Does that make the fieldset in error?这是否会使字段集出错? Or is it partially in error?还是部分错误? Perhaps you have a design where it makes sense to have the fieldset in error, but that is probably an exception rather than the rule.也许您的设计让字段集出错是有意义的,但这可能是一个例外而不是规则。

Technically, from an html spec perspective, it is valid to set aria-invalid on a fieldset ( https://www.w3.org/TR/html51/sec-forms.html#the-fieldset-element ).从技术上讲,从 html 规范的角度来看,在字段集 ( https://www.w3.org/TR/html51/sec-forms.html#the-fieldset-element ) 上设置aria-invalid是有效的。 See "Allowed ARIA state and property attributes".请参阅“允许的 ARIA 状态和属性属性”。

I am confused, though, by your original question.不过,我对你最初的问题感到困惑。 You want to set aria-invalid on a checkbox?您想在复选框上设置 aria-invalid 吗? How does a checkbox become invalid?复选框如何失效? It's either checked or not.它要么被检查,要么不被检查。 Do you put the user in a scenario where checking the box isn't valid?您是否将用户置于选中该框无效的场景中? If so, shouldn't the checkbox be disabled?如果是这样,不应该禁用复选框吗?

And for aria-describedby , you'll want to test that with various browsers and screen readers.对于aria-describedby ,您需要使用各种浏览器和屏幕阅读器对其进行测试。 Sometimes the label associated with aria-describedby isn't read immediately.有时与aria-describedby关联的标签不会立即读取。 There can be a pause, or the screen might say to hit alt+ <somekey> to hear the description.可能会有一个暂停,或者屏幕可能会说按 alt+ <somekey>来听取描述。 aria-labelledby , on the other hand, is read immediately.另一方面, aria-labelledby会立即读取。

I have a checkbox set as a form element and need to use aria-invalid and aria-describedby attributes on them.我有一个复选框设置为表单元素,需要对它们使用aria-invalidaria-describedby属性。 Should the attribute be written on every single checkbox or on a fieldset?属性应该写在每个复选框上还是字段集上?

From a theorical point of view, it makes more sense to set it on a fieldset .从理论的角度来看,将其设置在fieldset上更有意义。

An individual checkbox has only two states, and I can't see how one individual checkbox within a fieldset could have an error, except when there's only one checkbox (license agreement for instance)单个复选框只有两种状态,我看不到字段集中的单个复选框如何出错,除非只有一个复选框(例如许可协议)

For the same reason if your aria-describedby point to the error message, it has to be on the same element.出于同样的原因,如果您的aria-describedby指向错误消息,则它必须位于同一元素上。

Tenon team has researched that case thoroughly and came to the conclusion of not using aria attributes at all since the results in various screen readers are discouraging. Tenon团队对该案例进行了彻底的研究,并得出了根本不使用 aria 属性的结论,因为各种屏幕阅读器的结果令人沮丧。

There solution/ suggestion is the next:有解决方案/建议是下一个:

Dynamically injecting the error text into the legend .将错误文本动态注入到图例中 Our winning combination came from completely stepping away from the tried and tested aria-describedby and manipulating the legend text based on the current validity state of the control.我们的获胜组合来自完全摆脱久经考验的 aria-descriptionby 并根据控件的当前有效性状态操纵图例文本。 When an error occurred we appended it to the text in the legend and removed it again if no error condition existed.发生错误时,我们将其附加到图例中的文本中,如果不存在错误条件,则再次将其删除。

Check their blog post for more details on the subject.查看他们的博客文章以获取有关该主题的更多详细信息。

You shouldn't set the attributes on all elements but you could set the aria-invalid to true for the first check box only.您不应该在所有元素上设置属性,但您可以仅将第一个复选框的 aria-invalid 设置为 true。

Example:例子:

<input name="nom" aria-invalid="false"
    onclick="checkValidity('nom', ' ', 'your message 1');">
<br />
<input name="courriel" aria-invalid="false"
    onclick="checkValidity('courriel', '@', 'your second message);">

//js
<script type="text/javascript>
  var checkValidity = function(aID, aMsg){
  var elem = this,
    invalid = (elem.value.indexOf(aSearchTerm) < 0);
  if (invalid) {
   elem.setAttribute("aria-invalid", "true");
   updateAlert(aMsg);
  }  else {
   elem.setAttribute("aria-invalid", "false");
 }
}
</script>

OR you can use JQuery或者你可以使用 JQuery

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

相关问题 如何自动将“aria-描述的属性”添加到 uib-tooltip - How to add "aria-describedby attribute" to the uib-tooltip automatically 如何在输入表单中检查Aria无效 - How to check Aria-Invalid in an Input Form NVDA无法读取带有aria标签描述的aria - NVDA doesn't read aria-describedby with aria-label 是否仍然可以访问由值动态描述的aria描述? - Are dynamically generated aria-describedby values still accessible? 使用jQuery Validation Unobtrusive时描述的aria的多个值 - Multiple values for aria-describedby when using jQuery Validation Unobtrusive VoiceOver:aria-describedby / aria-labelledby 不适用于 svg-path - VoiceOver: aria-describedby / aria-labelledby is not working on svg-path 当 aria-live 区域第一次更新时,aria- describeby 会重复 - aria-describedby repeats when aria-live region updates for the first time 咏叹调的说明和例子,咏叹调无效,咏叹调扩大 - Explanation and example of aria-owns, aria-invalid, aria-expanded npm 开始显示错误 角色无线电不支持属性 aria-invalid。 此角色隐含在元素输入中 - npm start showing error The attribute aria-invalid is not supported by the role radio. This role is implicit on the element input 如何将aria属性设置为highcharts工具提示 - How to set aria attributes to highcharts tooltips
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM