简体   繁体   English

“返回顶部”链接可访问性

[英]"Back to Top" link accessibility

I am working on a web page where user has to scroll a lot.我正在处理 web 页面,用户必须滚动很多。

For ease of use, I have added the back-to-top link at the bottom of the page, so user can navigate to the top of the page.为了方便使用,我在页面底部添加了返回顶部链接,以便用户可以导航到页面顶部。

Now I have a html markup like this:现在我有一个 html 标记,如下所示:

<a class="btn-primary" href="#top">
<span class="btn-content link-content">
<svg focusable="false"><use xlink:href="#arrow-upward"></use></svg>
</span>
</a>

How can I make my link more accessible?如何使我的链接更易于访问? I have thought of adding aria-label , but other than that nothing crosses my mind我曾想过添加aria-label ,但除此之外,我没有想到

First of all, render your component usable, for example by following NNg's Back-to-Top Button Design Guidelines .首先,使您的组件可用,例如遵循NNg 的 Back-to-Top Button Design Guidelines This is a solid basis.这是一个坚实的基础。 Thanks to @outis for the hint.感谢@outis 的提示。

Here are some accessibility concerns that come to mind with regards to such a Back to top component.以下是关于此类返回顶部组件的一些可访问性问题。

Alternative text/accessible name替代文本/可访问名称

Every interactive element needs an accessible name.每个交互元素都需要一个可访问的名称。 This text is not only what gets read by a screen reader when focussing the element, but also how voice control can identify the button, as in “Click on back to top”.此文本不仅是屏幕阅读器在聚焦元素时读取的内容,也是语音控制如何识别按钮,如“单击返回顶部”。

Accompanying text for sighted users为有视力的用户提供附带文字

Adding a tooltip for sighted users via the title attribute is always a good idea as well, but you should never rely on that attribute to provide an accessible name, as implementation in screen readers is not good.通过title属性为有视力的用户添加工具提示也是一个好主意,但您永远不应该依赖该属性来提供可访问的名称,因为在屏幕阅读器中的实现并不好。

Even better would be having the text always visible for everyone.更好的是让每个人都可以看到文本。 Not everyone gets icons correctly .不是每个人都能正确获得图标

That way you also provide a very visible hint to voice command users.这样,您还可以向语音命令用户提供非常明显的提示。 The visible part needs to be included in the accessible name (alt text) for this reason.出于这个原因, 可见部分需要包含在可访问名称(替代文本)中。 You should add role="presentation" to the SVG if you have accessible text next to it.如果旁边有可访问的文本,则应将role="presentation"添加到 SVG。

一个向上箭头,后跟单词 Back to top

This is an example from the GOV.UK Design System Guidelines , who care a great deal about accessibility.这是GOV.UK 设计系统指南中的一个示例,他们非常关心可访问性。 They add it just before the footer on long pages.他们在长页面的页脚之前添加它。

Contrast对比

Since you didn't share your CSS, we don't know what it does with colours.由于您没有分享您的 CSS,我们不知道它对颜色有什么作用。 You need to make sure that the icon and text's contrast with the background are still 4.5:1 or above.您需要确保图标和文字与背景的对比度仍为 4.5:1 或以上。

Avoid icon-fonts避免使用图标字体

You already got that right.你已经猜对了。 (: (:

Since users with reading disorders often make their browser use a font they can read well, icon-fonts will break and remove icons that—ironically—would help them most.由于阅读障碍的用户经常让他们的浏览器使用他们可以很好阅读的字体,因此图标字体会破坏并删除图标——具有讽刺意味的是——这对他们最有帮助。

Be careful with animated scroll小心动画滚动

Often developers (or designers?) like to fly back to the top instead of the instant jump.通常开发人员(或设计师?)喜欢飞回顶部而不是立即跳跃。 This can help users orientate.这可以帮助用户定位。

Nowadays we can simply specify this with scroll-behaviour: smooth and let the browser do the work.现在我们可以简单地用scroll-behaviour: smooth来指定它,让浏览器完成工作。

However you implement this, you should be careful to not cause vertigo in people who are sensitive to these zoom animations.无论您如何实现这一点,您都应该小心不要让对这些缩放动画敏感的人感到眩晕。 Only apply this if the user can and did not set prefers-reduced-motion仅当用户可以且未设置prefers-reduced-motion时才应用此选项

Focus重点

While it is important to include the button in the tab order, it should probably come right before the footer, even when it's visible all the time.虽然在 Tab 键顺序中包含按钮很重要,但它可能应该出现在页脚之前,即使它一直可见。

Focus needs to be visible, of course, as for all interactive elements.当然,与所有交互元素一样,焦点需要可见。

Keyboard users can easily jump back to top by using their Home key, so it's less important to have the button in early in focus order or after each chapter or something.键盘用户可以使用他们的Home键轻松地跳回顶部,因此在焦点顺序的早期或在每个章节或其他内容之后将按钮设置为不太重要。

When the button disappears when arriving on top, focus needs to be put somewhere else, it must not be “lost” (going to body or html).当按钮到达顶部时消失,焦点需要放在其他地方,它不能“丢失”(转到正文或html)。

Refer to the WCAG参考 WCAG

I might have missed some criteria in this answer.我可能错过了这个答案中的一些标准。

If you want to be sure, you can open up the WCAG-EM Report Tool and start creating a report for your component.如果您想确定,您可以打开WCAG-EM 报告工具并开始为您的组件创建报告。

All criteria of the Web Content Accessibility Criteria will need to be audited by you. Web 内容可访问性标准的所有标准都需要由您审核。 This is the industry standard for accessible web applications, and legally binding in a lot of states.这是可访问的 web 应用程序的行业标准,在许多州具有法律约束力。

You can also add the Title attribute in your anchor tag您还可以在锚标记中添加 Title 属性

<a class="btn-primary" href="#top" title="go to top of page">

When working on the in-page navigation links, we should not forget the screen reader users, so we must ensure they know the purpose of the link.在处理页内导航链接时,我们不应该忘记屏幕阅读器用户,因此我们必须确保他们知道链接的目的。 A common way is an aria-label attribute specifying a meaningful value, such as 'Go to top' or 'Back to top'.一种常见的方法是使用 aria-label 属性指定一个有意义的值,例如“Go to top”或“Back to top”。 Once the aria-label is specified, the content of the link should be hidden from the screen reader (Exceptions exist) ie: via aria-hidden='true'.一旦指定了 aria-label,链接的内容应该对屏幕阅读器隐藏(存在例外),即:通过 aria-hidden='true'。

Another detail that should not be forgotten is the focus handling.另一个不应忘记的细节是焦点处理。 By default, most of the browsers just scroll the page when using an #Element's_ID for the href if the id does not exist, and SR/Keyboard users will be affected in such a way that after the page is scrolled to top and Tab key is pressed the focus will move to the next focusable element before the page was scrolled up, so, the result will be, an undesired page scroll down.默认情况下,如果 id 不存在,大多数浏览器在使用#Element's_ID作为 href 时只会滚动页面,并且 SR/Keyboard 用户将受到影响,页面滚动到顶部和 Tab 后按下键,焦点将在页面向上滚动之前移动到下一个可聚焦元素,因此,结果将是一个不希望的页面向下滚动。

There is a working implementation in W3C patterns page https://www.w3.org/WAI/ARIA/apg/patterns/ . W3C 模式页面https://www.w3.org/WAI/ARIA/apg/patterns/中有一个工作实现。

Hope this helps in your accessibility journey.希望这对您的无障碍之旅有所帮助。 The a11y world needs lot of people interested on it. a11y 世界需要很多对此感兴趣的人。

    <body id="top">
    ...
      <a class="btn-primary" aria-label="Back to top" href="#top">...
      </a>
...
    </body>

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

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