简体   繁体   English

如何使屏幕阅读器读取列表?

[英]How to make screen reader reads a list?

I would like to use the screen reader for accessibility purpose in order to read the text in a list, I found out some example on the web that make it work when the items of <li> wrapped with <a> . 我想使用屏幕阅读器来实现可访问性,以便阅读列表中的文本。我在网络上找到了一些示例,当<li>的项目用<a>包裹时,该示例可以正常工作。

I tried something like the following but it doesn't work: 我尝试了以下类似的操作,但不起作用:

<ul role="list">
  <li role="listitem">
    <div><h3 aria-label="item 1">item 1</h3></div>
  </li>
  <li role="listitem">
    <div><h3 aria-label="item 2">item 2</h3></div>
  </li>
  <li role="listitem">
    <div><h3 aria-label="item 2">item 3</h3></div>
  </li>
  <li role="listitem">
    <div><h3 aria-label="item 4">itwem 4</h3></div>
  </li>
</ul>

Hope you can help me with that. 希望你能帮助我。

The #1 rule for using ARIA (both aria-* attributes and the role attribute) is to not use it if you don't have to. 使用ARIAaria-*属性和role属性)的#1规则不必使用它。 Your code sample, while valid, has too much aria, all of it superfluous. 您的代码示例虽然有效,但咏叹调过多,所有这些都是多余的。

A <ul> has a role=list by default and the spec specifically says not to set the role. 默认情况下, <ul>具有一个role = list, 规范特别指出不要设置该角色。

Same with the <li> element. <li>元素相同。

The accessible name for your headings ( <h3> ) will come from the text content of the heading, according to step 2F of the " Accessible Name and Description Computation ", so having an aria-label for the <h3> is not necessary. 根据“ 可访问名称和描述计算 ”的步骤2F,您标题的可访问名称( <h3> )将来自标题的文本内容,因此不必为<h3> aria-label

So, your code sample is exactly the same as this code snippet: 因此,您的代码示例与此代码段完全相同

<ul>
  <li>
    <div>
      <h3>item 1</h3>
    </div>
  </li>
  <li>
    <div>
      <h3>item 2</h3>
    </div>
  </li>
  <li>
    <div>
      <h3>item 3</h3>
    </div>
  </li>
  <li>
    <div>
      <h3>item 4</h3>
    </div>
  </li>
</ul>

Lists, in general, are not keyboard focusable so you won't navigate to them with the TAB key. 通常,列表不能集中在键盘上,因此您不会使用TAB键导航到它们。 I think that's why you mentioned wrapping the list item in an anchor tag, <a> , to allow you to TAB to the link. 我认为这就是为什么您提到将列表项包装在锚标记<a> ,以允许您将TAB链接到该链接的原因。

The way a screen reader user will navigate to a list is with shortcut keys. 屏幕阅读器用户导航到列表的方式是使用快捷键。 Both JAWS and NVDA use the L key to navigate to a list and the I ('eye') key to navigate to a list item. JAWS和NVDA都使用L键导航到列表,并使用I (“眼睛”)键导航到列表项。 A screen reader user can also walk the DOM using the up/down arrow keys. 屏幕阅读器用户还可以使用向上/向下箭头键浏览DOM。 VoiceOver users on iOS devices can set their rotor to "Lists" and can then swipe up/down to the next list. iOS设备上的VoiceOver用户可以将其转子设置为“列表”,然后可以向上/向下滑动到下一个列表。

So, if you are trying to force lists to be focusable using the keyboard, you would be doing a screen reader user a disservice because they're not used to navigating to a list in that manner. 因此,如果您尝试使用键盘强制列表变得可聚焦,那么屏幕阅读器用户将受到损害,因为他们不习惯以这种方式导航到列表。 Non-interactive elements (such as <ul> or <p> or <h3> ) should not be keyboard focusable. 非交互式元素(例如<ul><p><h3> )不应是键盘可聚焦的。

暂无
暂无

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

相关问题 如何让屏幕阅读器 NVDA 在 listitem (ARIA) 上按下 ENTER 键? - How can I make screen reader NVDA reads ENTER key when press it on listitem (ARIA)? 如何使屏幕阅读器读取“ x个项目的列表”列表 - How to make the screen reader read a list as “list of x number of items” 屏幕阅读器会读取所有内容,但不会对其进行制表 - Screen reader reads it all, but does not tab to it 如何停止屏幕阅读器以读取具有角色 =“警报”的所有错误跨度标记? - How to stop Screen reader to reads all errors span tag which has role=“alert”? Web 辅助功能 - 屏幕阅读器在鼠标 hover 和标签上以不同方式读取 HTML 元素 - Web Accessibility - Screen Reader reads HTML element differently on mouse hover and on tabbing 如果用户尝试提交无效信息,如何让屏幕阅读器读出出现的验证错误文本? - How to make screen reader read out a validation error text that appears if the user tries to submit invalid information? 如何使屏幕阅读器用户可以访问必填字段和表单验证的指示? - How to make indication of mandatory fields and form's validation accessible for screen reader users? 如何使JAWS屏幕阅读器阅读标题文件,逐字逐句而不是句子阅读? - how to make JAWS screen reader to read the title document to read separately letter by letter instead of sentence? 如何让屏幕阅读器读出混合的文本和组件? - How can I make a screen reader read out a mix of text and components? 如果初始焦点设置为另一个元素,如何让屏幕阅读器在安装时读取组件中的标题? - How to make screen reader read a heading in a component on mount if initial focus is set to another element?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM