简体   繁体   English

使用aria标签作为内容是否不好?

[英]Is it bad to use aria-label for content?

I've a case where I'd like to use aria-label to give screen-readers access to the (CSS pseudo-)content. 我有一种情况,我想使用aria-label来使屏幕阅读器访问(CSS伪)内容。 Something like this: 像这样:

 [data-pseudo-content]::before { content: attr(data-pseudo-content); } 
 <h1 aria-label="This is the title" data-pseudo-content="This is the title"></h1> 

Is it bad to use aria-label for content rather than a label for the content? 对内容使用aria-label而不是对内容使用aria-label是否不好? Also, would some screen-readers read This is the title twice? 另外,某些屏幕阅读器会两次读取This is the title吗?

To the best of my understanding, aria-label can be applied in some situations to change or enrich the accessible name of an element (= the textual representation that will be outputted to the user, either by speech or by braille). 据我所知,可以在某些情况下使用aria标签来更改或丰富元素的可访问名称(=将通过语音或盲文输出给用户的文本表示形式)。 The amount of influence of aria-label or aria-labelledBy on the accessible name depends on how much information the node contains and its type or role itself. aria-label或aria-labeledBy对可访问名称的影响程度取决于节点包含多少信息及其节点的类型或角色本身。

Your example (confirmed with NVDA on Windows 8.1 in Chrome 42 and Firefox 36) doesn't make much of a difference for a screen reader, as it will follow a set of rules to determine the accessible name. 您的示例(已在Chrome 42和Firefox 36的Windows 8.1上通过NVDA确认)对于屏幕阅读器没有太大的不同,因为它将遵循一系列规则来确定可访问的名称。 In my experience, a screen reader will - among others - give priority to the containing text if other conditions (role) fail. 以我的经验,如果其他条件(角色)失败,屏幕阅读器将优先考虑所包含的文本。 If the node would happen to be empty and other alternatives are not available, a screen reader will render aria-labelledBy or aria-describedBy as the accessible name if provided. 如果该节点碰巧是空的,并且其他替代方法不可用,则屏幕阅读器将提供aria-labelledBy或aria- describeBy作为可访问名称(如果提供)。 Otherwise it will be ignored. 否则它将被忽略。

Luckily in your case, the ARIA standard also covers :before and :after as part as the algorithm for determining the accessible name. 幸运的是,ARIA标准还包含:before和:after作为确定可访问名称的算法的一部分。 You can read more about how the accessible name is being computed at the spec: http://www.w3.org/TR/wai-aria/roles#textalternativecomputation 您可以在规范中阅读有关如何计算可访问名称的更多信息: http : //www.w3.org/TR/wai-aria/roles#textalternativecomputation

When would aria-label or aria-labelledBy make a good use? 什么时候可以使用aria标签或aria标签标签? I'm still researching the subject, so I cannot provide a 100% certain answer for the time being. 我仍在研究该主题,因此暂时无法提供100%的肯定答案。 I do, however know that it makes a difference on elements like <input> . 但是,我确实知道,这对像<input>这样的元素产生了影响。 You should apply aria-label when there is no visible label available. 如果没有可用的可见标签,则应应用aria标签。 It might also be useful to know that, whenever aria-labelledBy is rendered, it will always be placed first in the accessible name. 知道,每当渲染aria-labeledBy时,它将始终始终放在可访问名称中可能会很有用。 This could be useful for form fields, because <label> might not always be rendered first if many attributes are given. 这对于表单字段可能很有用,因为如果给定了许多属性, <label>可能不会总是先呈现。 aria-label / aria-labelledBy are also useful when you use the contenteditable attribute on an element, to make sure that the content is accessible for screen readers. aria-label / aria-labelledBy在元素上使用contenteditable属性时也很有用,以确保屏幕阅读器可以访问内容。

Here is a wiki with some examples of how aria-label / aria-labelledBy could be applied (search on page for those words): http://www.w3.org/WAI/GL/wiki/Category:ARIA_Techniques 这是一个Wiki,其中包含如何应用aria-label / aria-labelledBy的一些示例(在页面上搜索这些词): http : //www.w3.org/WAI/GL/wiki/Category : ARIA_Techniques

Remember: the best way to figure out what works and what doesn't, is by playing around with a screenreader. 请记住:找出有效的方法和无效的最佳方法是通过使用屏幕阅读器。 I have not been able to test with other screen readers (apart from NVDA and iOs VoiceOver for a while), so the implementation on other screen readers like JAWS might differ. 我暂时无法使用其他屏幕阅读器(除了NVDA和iOs VoiceOver进行测试),因此在其他屏幕阅读器(如JAWS)上的实现可能有所不同。 Other known screen readers are Windows Eyes and Supernova (though I heard that SN is not good with replacing focus with .focus(), so be careful). 其他已知的屏幕阅读器是Windows Eyes和Supernova(尽管我听说SN用.focus()代替focus不好,所以要小心)。 It might also be a good idea to test in different browsers, as the accessibility API might differ and give slightly different outputs. 在不同的浏览器中进行测试可能也是一个好主意,因为可访问性API可能会有所不同,并且输出会略有不同。

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

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