屏幕读取器在Mac Chrome上正确阅读,但在Windows Chrome上没有读取

发布于 2025-01-23 21:51:22 字数 659 浏览 5 评论 0原文

我有一个场景,我添加了一个aria-label向父< div; gt;,其中包含一些文本。理想情况下,应先叙述给父< div> div; div; div>aria-label应首先叙述,然后再叙述子文本组件。这在MacOS Chrome上与VoiceOver屏幕阅读器完全效果,但是在Windows Chrome上,nvda parent < div> aria-label根本没有阅读。

附加代码片段以供参考:

<div aria-label="Parent div accessibility">
     <Text> Some Text </Text> 
</div>

Macos Chrome上的语音输出与VoiceOver:

Narrator - Parent div accessibility
Narrator - Some Text

Windows Chrome上的语音输出与NVDA:

Narrator - Some Text

I have a scenario where I have added an aria-label to a parent <div> which contains some text. Ideally the aria-label provided to the parent <div> should be narrated first and then the child Text component. This works completely fine on MacOS Chrome with the VoiceOver screen reader, but on Windows Chrome with NVDA the parent <div> aria-label is not at all read.

Attaching a code snippet for reference:

<div aria-label="Parent div accessibility">
     <Text> Some Text </Text> 
</div>

Speech output on MacOS Chrome with VoiceOver:

Narrator - Parent div accessibility
Narrator - Some Text

Speech output on Windows Chrome with NVDA:

Narrator - Some Text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忱杏 2025-01-30 21:51:22

屏幕读取器在非相互作用元素上解释aria-label方面都在地图上。

根据 David MacDonald的测试在静态元素上读取aria-label文本,但是除非静态内容(例如&lt; div&gt;)具有remo =',否则jaws和nvda不会导航“角色=“ search”real =“ main”real =“ img”

根据设计,aria-label旨在覆盖元素的现有文本,因为它是大多数屏幕读取器将其解释为元素标签的方法。因此,您从配音中获得的行为不一定是标准行为。某些屏幕读取器(例如对话)会忽略&lt; div&gt;的内部文本,如果您使用aria-label,因为它可以解释aria-label < /代码>作为该元素的标签,忽略了元素中的任何其他文本。其他屏幕读取器(如Jaws)将读取 aria-label文本和&lt; div; div&gt; 的内部文本em>您将角色添加到静态元素之类的角色=“ navigation”。似乎NVDA 2018在静态元素上使用aria-label确实支持,但后来被删除,因为aria-label辩论尚未达成共识。

选项1

失败安全选项将是使用CSS明显隐藏的文本。所有浏览器/屏幕读取器组合都完全支持这一点。

这是示例 webaim

<style>
    .sr-only {
    position:absolute;
    left:-10000px;
    top:auto;
    width:1px;
    height:1px;
    overflow:hidden;
    }
</style>
<div class="sr-only">This text is hidden.</div> 

option

2 > content 属性隐藏了屏幕读取器要说的文本,如 so so 上的类似问题:

<style>
    div::before {content: "This text is hidden"; font-size: 0px;}  
</style>

我用jaws和nvda测试了他的建议,它宣布了“这本文是隐藏的“文本以及&lt; div&gt;的内部文本。

但是,正如Quentinc在注释中指出的那样,CSS content属性当前不受所有浏览器/屏幕读取器组合的支持。

参考:
澄清在没有角色#756
的元素上使用aria-label
woe-aria: - 标签/ledby
Aria-labelledby,aria-label和aria-descred a aria-labelledby会发生什么情况在静态HTML元素上?
webaim:webaim:仅适用于屏幕阅读器用户的隐形

内容 使用CSS隐藏文本。

Screen readers are all over the map with respect to interpretting aria-label on non-interactive elements.

According to David MacDonald's tests, VoiceOver and TalkBack will read the aria-label text on static elements, but JAWS and NVDA will not unless the static content (like a <div>) has the role="navigation", role="search", role="main", or role="img".

By design, aria-label is meant to override the existing text of an element because it is what most screen readers will interpret as the element's label. So, the behaviour you're getting from VoiceOver is not necessarily standard behaviour. Some screen readers (like TalkBack) will ignore the inner text of your <div> if you use aria-label, because it interprets the aria-label as the label for that element and ignores any other text within the element. Other screen readers like JAWS will read both the aria-label text and the inner text of the <div> if you add a role like role="navigation" to your static element. It seems that NVDA 2018 did support using aria-label on static elements, but it was later removed because there's yet to be consensus on the aria-label debate.

Option 1

The fail-safe option would be to use text that is visibly hidden by CSS. This is fully supported by all browser/screen reader combinations.

Here is the example suggested by WebAIM:

<style>
    .sr-only {
    position:absolute;
    left:-10000px;
    top:auto;
    width:1px;
    height:1px;
    overflow:hidden;
    }
</style>
<div class="sr-only">This text is hidden.</div> 

Option 2

Another option is to use the CSS content property to hide the text that you want spoken by the screen reader, as suggested by slugolicious in a similar question on SO:

<style>
    div::before {content: "This text is hidden"; font-size: 0px;}  
</style>

I tested his suggestion with JAWS and NVDA and it announced the "This text is hidden" text as well as the inner text of the <div>.

However, as QuentinC pointed out in the comments, the CSS content property isn't currently supported by all browser/screen reader combinations.

For reference:
Clarify use of aria-label on elements with no role #756
Woe-ARIA: The Surprisingly but Ridiculously Complicated World of aria-label/ledby
What happens with aria-labelledby, aria-label and aria-describedby on static HTML elements?
WebAIM: Invisible Content Just for Screen Reader Users

Update

I edited my original answer to include QuentinC's suggestion of using CSS to hide the text.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文