简体   繁体   English

如果不存在合适的ARIA属性,我应该使用自定义ARIA属性吗?

[英]Should I use a custom ARIA attribute if there is no suitable ARIA attribute exists?

I want to identify an element can be hidden automatically(using JavaScript to do it) when the user clicks its descendants. 我想确定一个元素可以在用户单击其后代时自动隐藏(使用JavaScript来实现)。

for example: 例如:

<div>
    <div aria-autohide>
        <a href="http://..." target="_blank">A Link</a>
    </div>
</div>

Is it a proper way to do it? 这是正确的方法吗?

While you can create custom HTML tags and you can create custom attributes , typically prefaced with " data- ", you cannot create custom ARIA attributes. 虽然您可以创建自定义HTML标签,并且可以创建自定义属性 (通常以“ data- ”开头),但是您无法创建自定义ARIA属性。 There's a predefined list of ARIA attributes that are mapped to certain properties in the accessibility API . 在可访问性API中有一个预定义的ARIA属性列表,这些属性映射到某些属性 If you make up a new one, there's no way for you to tell the accessibility API what the attribute means and how it should be interpreted by assistive technology, such as a screen reader. 如果您要组成一个新的,则无法告诉辅助功能API该属性的含义以及辅助技术(例如屏幕阅读器)应如何解释该属性。

The best you can do for now is add visually hidden text to your element so that the screen reader reads it when focus (whether keyboard focus or screen reader focus) moves to the element. 现在,您能做的最好的就是将视觉上隐藏的文本添加到元素中,以便屏幕阅读器在焦点(无论是键盘焦点还是屏幕阅读器焦点)移到元素时读取它。

For example, 例如,

<div>
  <div>
    <a href="http://..." target="_blank">A Link <span class="sr-only">selecting this link will cause this element to be hidden</span></a>
  </div>
</div>

See What is sr-only in Bootstrap 3? 请参阅Bootstrap 3中的什么是sr-only? for information on the "sr-only" class. 有关“仅sr”类的信息。

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

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