简体   繁体   English

为屏幕阅读器制作可制表符的文本

[英]Make text tab-able for screen reader

I have some text that displays if there is an error如果出现错误,我会显示一些文本

<div>Error message</div>

When the error div is displayed I want the user to be able to tab with their keyboard over this so it can be read by a screen reader so it is accessible for everybody.当显示错误 div 时,我希望用户能够使用键盘在上面切换,这样它就可以被屏幕阅读器读取,这样每个人都可以访问它。

While there is a simple way to accomplish this, it is not how screen reader users would expect an error message to be used: Expectation is to have the error when focussing the input element itself.虽然有一种简单的方法可以实现这一点,但这并不是屏幕阅读器用户所期望的错误消息的使用方式:期望是在聚焦输入元素本身时出现错误。

Screen reader support is not rendering content accessible to everybody.屏幕阅读器支持并不是呈现每个人都可以访问的内容。 There are plenty different kinds of disabilities, and only some users benefit from screen readers.有很多不同类型的残疾,只有一些用户受益于屏幕阅读器。 For others, other techniques are necessary.对于其他人,其他技术是必要的。

For example, colour contrasts and a layout that does not break when font size is increased helps users with visual impairments, and keyboard focus needs to be visible for those who can see but navigate by means of keyboard.例如,颜色对比和在字体大小增加时不会中断的布局可以帮助有视觉障碍的用户,对于那些可以看到但通过键盘导航的用户来说,键盘焦点需要可见。

As a start, I recommend the W3C's Stories of Web Users in How People with Disabilities Use the Web to get an idea.作为开始,我推荐 W3C 的Web 用户故事中的残障人士如何使用 Web来了解一下。 The other articles and videos on that site are very well done, as well.该网站上的其他文章和视频也做得很好。

The foundation for any accessibility technique is to properly structure HTML, use headlines and landmarks for orientation, and use semantic tags instead of generic <div> .任何可访问性技术的基础都是正确构建 HTML,使用标题和地标来定位,并使用语义标签而不是通用的<div>

How screen reader users navigate屏幕阅读器用户如何导航

There are several ways to navigate a document/a page with a screen reader, depending on current use case:根据当前用例,有多种使用屏幕阅读器浏览文档/页面的方法:

  • Simply read all elements on the page (including text)只需阅读页面上的所有元素(包括文本)
  • Read the next/previous block of content阅读下一个/上一个内容块
  • Navigate to a heading via a list of headings通过标题列表导航到标题
  • Navigate to a landmark/form from a list of landmarks从地标列表导航到地标/表单
  • Navigate to a link via a list of links通过链接列表导航到链接
  • Navigate to the next/previous interactive element by means of tab通过选项卡导航到下一个/上一个交互元素

Aspects to render an error message helpful to screen readers呈现有助于屏幕阅读器的错误消息的方面

It should never be necessary for a (screen reader) user navigate/explore the site to see whether there was an error. (屏幕阅读器)用户永远不需要浏览/浏览网站来查看是否有错误。 The error should be announced immediately after the intended interaction.应该在预期的交互之后立即宣布错误。

How to achieve this, depends on how you are running form validation.如何实现这一点取决于您如何运行表单验证。 Inline, server- or client side.内联、服务器端或客户端。 Web AIM have a great article on Usable and Accessible Form Validation and Error Recovery . Web AIM 有一篇关于可用和可访问的表单验证和错误恢复的好文章。

For example, if your error message is related to an input field, and you have client-side validation, it is very important to establish the relationship between them, which is often achieved by means of aria-describedby .例如,如果您的错误消息与输入字段相关,并且您有客户端验证,那么建立它们之间的关系非常重要,这通常是通过aria-describedby来实现的。

<label>Name
  <input type="text" name="name" autocomplete="name" aria-invalid="true" aria-describedby="name-err">
</label>
<div id="name-err">Please provide a name</div>

If validation is run on Submit, a best practice is to set focus to the first input in error via JavaScript .focus() .如果在提交时运行验证,最佳做法是通过 JavaScript .focus()将焦点设置到第一个错误输入。

How to make any element tab-able如何使任何元素都可以制表

The tabindex attribute will render any element reachable by means of tab . tabindex 属性将呈现任何可通过tab访问的元素。 You should not set it to a positive value.您不应将其设置为正值。

<div tabindex="0">Error message</div>

If you want an element to receive focus only programmatically by means of JavaScript (on submit, for example), but not by means of tab , you can use tabindex="-1" .如果您希望某个元素仅通过 JavaScript(例如,在提交时)以编程方式接收焦点,而不是通过tab方式,您可以使用tabindex="-1"

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

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