简体   繁体   English

使用 JAWS 时如何使 div 元素可通过箭头键导航

[英]How to make a div element navigable by arrow keys when using JAWS

I would like to make a div element navigable by arrow keys when JAWS is running.我想在 JAWS 运行时使一个div元素可以通过箭头键导航。 The div should not be navigable using the TAB key; div不应使用TAB键导航; so using tabindex is not applicable.所以使用tabindex是不适用的。

Here is an example snippet of the html/reactjs structure.这是 html/reactjs 结构的示例片段。

const label1 = 'First label';
const label2 = 'Second label';
const prefix = 'Prefix';
const suffix = 'Suffix';

const screenReaderText = `${prefix} ${label1} ${suffix} ${label2}`;

return (
  <>
    <h1>Heading</h1>
    <div className="container" aria-label={screenReaderText}>
      <div aria-hidden="true">{label1}</div>
      <div aria-hidden="true">{label2}</div>
    </div>
    <footer>Footer</footer>
  </>
);

The two nested div should not be available to the accessibility API;两个嵌套的div不应该对无障碍 API 可用; hence the use of aria-hidden="true" .因此使用aria-hidden="true" The div with className="container" should be navigable by arrow keys when using JAWS.使用 JAWS 时, className="container"div应该可以通过箭头键导航。 Moreover, when navigating to the container div , JAWS should read out a label which is a combined and modified text of the contents the two inner div .此外,当导航到容器div时,JAWS 应该读出一个 label,它是两个内部div内容的组合和修改文本。

The navigation flow should be: h1 -> container div -> footer导航流程应该是: h1 -> 容器div -> footer

I am guessing I should apply an appropriate role to the container div .我猜我应该对容器div应用适当的role The tree role gives the desired effect, but reading about it suggests that it is not best practice for this use case. tree角色提供了预期的效果,但阅读它表明这不是此用例的最佳实践。

What are you navigating to when in the <div> if the child elements have aria-hidden="true" ?如果子元素具有aria-hidden="true" ,您在<div>中导航什么?

If you want the arrow keys to work then you need a role on your <div> that will cause JAWS (or NVDA) to automatically switch from browse mode to forms mode.如果您希望箭头键起作用,那么您需要在<div>上设置一个role ,该角色将导致 JAWS(或 NVDA)自动从浏览模式切换到 forms 模式。 The valid roles that do that are listed here: https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#x6-1-fundamental-keyboard-navigation-conventions此处列出了执行此操作的有效角色: https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#x6-1-fundamental-keyboard-navigation-conventions

To avoid confusion about “navigating” the element: You want a screen reader to read the text in browse mode like regular text, which JAWS already does by means of the arrow keys, line by line.为避免对“导航”元素的混淆:您希望屏幕阅读器像常规文本一样在浏览模式下阅读文本,JAWS 已经通过箭头键逐行读取文本。

Also, the whole text Prefix Label1 Suffix Label2 should be in a single line, even though it's visually presented in separate lines.此外,整个文本Prefix Label1 Suffix Label2应该在一行中,即使它在视觉上显示在单独的行中。

If you want text to be exposed only to assistive technology like screen readers, the famous visually-hidden CSS class comes into play (fka sr-only ).如果您希望文本显示给屏幕阅读器等辅助技术,则著名的visually-hidden CSS class 发挥作用(fka sr-only )。

There's a great explanation on how it works by Scott O'Hara: Inclusively Hidden Scott O'Hara 对它的工作原理进行了很好的解释:包容性隐藏

 /* ie9+ */.visually-hidden:not(:focus):not(:active) { clip: rect(0 0 0 0); clip-path: inset(50%); height: 1px; overflow: hidden; position: absolute; white-space: nowrap; width: 1px; }
 <h1>Heading</h1> <div className="container"> <div class="visually-hidden">Prefix Label1 Suffix Label2</div> <div aria-hidden="true">Label1</div> <div aria-hidden="true">Label2</div> </div> <footer>Footer</footer>

Why not aria-label ?为什么不aria-label

The accessible name of an element, provided by means of aria-label or aria-labelledby is not announced in browse mode (when reading).通过aria-labelaria-labelledby提供的元素的可访问名称在浏览模式下(阅读时)不会公布。

It is only used to build the lists of, fe headlines or landmarks, and in form mode, when navigating with Tab .它仅用于构建 fe 标题或地标的列表,并且在使用Tab导航时在表单模式下。

By default, the accessible name is built from the text contents, so using visually-hidden is taken into account, should you add a role or interaction.默认情况下,可访问的名称是根据文本内容构建的,因此如果您添加角色或交互,则考虑使用visually-hidden

Mismatch between visual and accessible text视觉文本和可访问文本之间的不匹配

Since the text in your question is probably not the one used in production, I'd like to point out that it's important to not divert too much between visual text and text accessible to assistive technology.由于您问题中的文本可能不是生产中使用的文本,因此我想指出,重要的是不要在视觉文本和辅助技术可访问的文本之间转移太多。

A lot of screen reader users are sighted, and rely on the two matching.很多屏幕阅读器用户是有视力的,并且依赖于两者的匹配。

For example, visually presenting the two labels in two separate lines creates the expectation for JAWS users that they'd need to use arrow down twice, not once.例如,将两个标签直观地显示在两个单独的行中,让 JAWS 用户期望他们需要使用两次向下箭头,而不是一次。

Also, how are sighted users making sense of the two labels without a screen reader, if prefix and suffix are missing?此外,如果缺少前缀和后缀,有视力的用户如何在没有屏幕阅读器的情况下理解这两个标签?

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

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