简体   繁体   English

NVDA 未正确宣布 aria-live 区域

[英]NVDA does not announce aria-live regions correctly

I'm in the process of making a React app as accessible as possible.我正在使 React 应用程序尽可能易于访问。 However, I'm noticing some weird behavior with NVDA - I have two live regions which I just cannot get NVDA to announce correctly.但是,我注意到 NVDA 有一些奇怪的行为——我有两个实时区域,我只是无法让 NVDA 正确宣布。 On Voiceover, everything works smoothly with these.在 Voiceover 上,一切都可以顺利进行。

First there is a notification component, which has generated HTML like this.首先有一个通知组件,它已经像这样生成了 HTML。 NVDA doesn't announce the notifications, Voiceover does: NVDA 不会公布通知,Voiceover 会:

<div aria-live="polite" aria-hidden="true/false">
  <article> <-- There might be many of these if there's multiple notifications, and there's none of these if there's no notifications
    <div>
      <div type="alert">
        <div>
          <div>The text here should be announced when shown</div>
        </div>
      </div>
    </div>
  </article>
</div>

If I remove aria-hidden from the first div, NVDA reads it, but it gets unreliable on Voiceover.如果我从第一个 div 中删除 aria-hidden,NVDA 会读取它,但它在 Voiceover 上变得不可靠。 Inside the first div, there is a PoseGroup component too, just doesn't show up on generated HTML.在第一个 div 中,也有一个 PoseGroup 组件,只是没有显示在生成的 HTML 上。

EDIT: I managed to get this working by wrapping the whole thing into yet another div with aria-live="polite".编辑:我设法通过使用 aria-live="polite" 将整个内容包装到另一个 div 中来实现这一点。 A little hacky solution but what you know... If someone has better solution, I'm listening.一个有点hacky的解决方案,但你知道...如果有人有更好的解决方案,我正在听。

Then there's a live chat, which has HTML like this:然后是一个实时聊天,它有这样的 HTML:

<div>
  <ul aria-live="polite"> <-- There are multiple of these depending on number of elements, but always at least one
    <li aria-hidden="true/false"> <--- There are many of these, some hidden from screen reader depending on the component, these are messages, timestamps etc, some of them should be read
      <div>
        <span>
          <div>
            <p aria-hidden="true">Visible message text</p>
            <p aria-hidden="false">Hidden visibility, but contains additional information to screen reader and should be read always</p>
         </div>
        </span>
      </div>
    </li>
  </ul>
</div>

Here, I'm using multiple aria-live containers which are spawned when there are enough messages on the former one, this is due to Voiceover stopping the reading when there are too many elements, and this solution works with it.在这里,我使用了多个 aria-live 容器,当前一个容器上有足够的消息时会生成这些容器,这是由于 Voiceover 在元素太多时停止读取,并且此解决方案适用于它。 It should be also noted that there is a PoseGroup component wrapping the li elements, it doesn't show on the generated HTML.还应该注意的是,有一个 PoseGroup 组件包装了 li 元素,它没有显示在生成的 HTML 上。 The li elements should only read the messages, no timestamps etc, that's why they have aria-hidden. li 元素应该只读取消息,没有时间戳等,这就是它们隐藏 aria 的原因。 No matter what I tried, NVDA doesn't read any of these.无论我尝试什么,NVDA 都不会读取其中的任何内容。 Voiceover works perfectly with this kind of code. Voiceover 与这种代码完美配合。 I have tried to convert the ul and li's to divs with no luck.我试图将 ul 和 li 转换为 div,但没有成功。

Then there's a form input component, which has an error label as a live region, goes like this:然后是一个表单输入组件,它有一个错误 label 作为活动区域,如下所示:

<label>
  <span>Some text</span>
  <input/>
  <div aria-live="polite">
    <span>This span is conditionally shown if there's an error.</span>
  </div>
</label>

This component however, works perfectly like this on both Voiceover and NVDA, and I just cannot get my head around why the other two don't.然而,这个组件在 Voiceover 和 NVDA 上都像这样完美地工作,我只是无法理解为什么其他两个没有。 Sure, they're more complex, but shouldn't it work on NVDA too since Voiceover does it without any difficulty?当然,它们更复杂,但它不应该也适用于 NVDA,因为 Voiceover 没有任何困难吗?

I still consider myself as an accessibility noob, and been banging my head against a wall for couple of days.我仍然认为自己是一个可访问的菜鸟,并且已经把头撞到墙上好几天了。

Live regions are a well supported and mature accessibility tool, but they aren't the most intuitive thing.实时区域是一种得到很好支持且成熟的可访问性工具,但它们并不是最直观的东西。 It's possible that you may be using them incorrectly.您可能会错误地使用它们。

Live regions are only announced when the content changes.实时区域仅在内容更改时才会公布。 If there's content present in the live region at the time of page load, it won't be announced unless that content changes.如果在页面加载时活动区域中存在内容,除非内容发生变化,否则不会公布。

I'm not sure if you're using aria-hidden as a toggle to show/hide content in the live region, but if so, that's probably the source of your problems.我不确定您是否使用aria-hidden作为切换来显示/隐藏实时区域中的内容,但如果是这样,那可能是您的问题的根源。 Your third example isn't using this technique, and it seems to be the one working.你的第三个例子没有使用这种技术,它似乎是一种工作。

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

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