简体   繁体   English

带有字体图标的按钮的辅助功能

[英]Accessibility for button with font icon in it

I'm having an accessibility problem with the button element. 我有按钮元素的可访问性问题。 I'm wondering if this is the good way to do it. 我想知道这是否是做到这一点的好方法。 I have a button and the only content is a Font-Awesome (font-icon) in it. 我有一个按钮,唯一的内容是Font-Awesome(字体图标)。 I was wondering if adding a title attribute to my button was enough to make it accessible ? 我想知道是否在我的按钮上添加title属性足以使其可访问?

Like this: 像这样:

<button class="prev" title="My accessible title">
   <i class="fa fa-chevron-circle-left"></i>
</button>

The correct property in this case should be aria-label or aria-labeledby : 在这种情况下,正确的属性应该是aria-labelaria-labeledby

<button class="prev" aria-label="My accessible title">
   <i class="fa fa-chevron-circle-left"></i>
</button>

With this, the screen reader for example will reproduce My accessible title instead the icon inside it. 有了这个,例如,屏幕阅读器将重现My accessible title而不是其中的图标。

See more: 看更多:

https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-label_attribute https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-label_attribute

https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-labelledby_attribute https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-labelledby_attribute

You have to use both title and aria-label attributes as some screenreaders does not read the title attribute, while other users won't benefit of the aria-label attribute. 您必须同时使用titlearia-label属性,因为某些屏幕阅读器不会读取title属性,而其他用户不会受益于aria-label属性。

You have to remember that accessibility does not only target screenreaders users but also every other people, so aria-label won't be sufficient. 您必须记住,可访问性不仅针对屏幕阅读器用户,而且针对所有其他人,因此aria-label不够。

Also note that, for better accessibility, you might want to add a way to show the description when you focus the button with the keyboard. 另请注意,为了更好地访问,您可能希望在使用键盘对焦按钮时添加一种显示说明的方法。 That would be a good idea. 那将是一个好主意。

That being said, I will be silly enough to suggest that some part of the description of your button might be always visible for better accessibility. 话虽如此,我会愚蠢地建议您的按钮的某些部分描述可能始终可见,以便更好地访问。

For instance, the following examples shows how the two attributes might be used conjointly with a short visible hint for a popup close button : 例如,以下示例显示了两个属性如何与弹出关闭按钮的短可见提示一起使用:

<button aria-label="Back to the page" title="Close popup">
  <i class="fa fa-times"></i>
  Close
</button>

The title attribute is the most widely supported attribute for assistive technologies. title属性是辅助技术最广泛支持的属性。 This includes Dragon ( which heavily relies on the title attribute for targeting elements ) as well as all modern screen readers that implement the ARIA accessible name computation algorithm and many older screen readers. 这包括Dragon( 严重依赖于目标元素的title属性 )以及实现ARIA可访问名称计算算法和许多旧屏幕阅读器的所有现代屏幕阅读器。

As can be seen in step D of that algorithm, the final element that is evaluated is the title attribute. 从该算法的步骤D中可以看出,评估的最终元素是title属性。

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

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