[英]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. 使用ARIA ( aria-*
属性和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.