简体   繁体   English

aria-scribedby 和多级 html 标签

[英]aria-describedby and multiple level html tags

Here is an example using aria-describedby这是一个使用aria-describedby的例子

<div role="application" aria-labelledby="calendar" aria-describedby="info">
    <h1 id="calendar">Calendar</h1>
    <p id="info">
        This calendar shows the game schedule for the Boston Red Sox.
    </p>
    <div role="grid">
        ...
    </div>
</div>

Say I changed to this:说我改成这样:

<div role="application" aria-labelledby="calendar" aria-describedby="info">
    <h1 id="calendar">Calendar</h1>
    <div id="info">
        <svg />
        <div></div>
        <div>
          <p>This calendar shows the game schedule for the Boston Red Sox.</p>
        </div>
    </div>
    <div role="grid">
        ...
    </div>
</div>

Is screen reader like NVDA still announces This calendar shows the game schedule for the Boston Red Sox same as the first example? NVDA 之类的屏幕阅读器是否仍会发布This calendar shows the game schedule for the Boston Red Sox与第一个示例相同?

Short Answer简答

The examples would both be announced as " calendar , This calendar shows the game schedule for the Boston Red Sox.** in the majority of screen reader / browser combos . This is assuming the SVG is handled correctly and the empty div you added is indeed empty (see end of this answer).这些示例都将宣布为“日历,此日历显示波士顿红袜队的比赛时间表。**在大多数屏幕阅读器/浏览器组合中。这是假设 SVG 处理正确并且您添加的空 div 确实是空(见本答案结尾)。

Long Answer长答案

aria-labelledby would be announced first, with aria-describedby announced second in most screen readers .在大多数屏幕阅读器中aria-labelledby将首先公布,而aria-describedby公布其次。

They are not normally used together on the same element as both can contain a list of IDs to announce.它们通常不会在同一个元素上一起使用,因为两者都可以包含要声明的 ID 列表。

I would suggest that for ease of maintenance you change it to:-我建议为了便于维护,您将其更改为:-

aria-labelledby="calendar info" , this would ensure reading order is consistent across all browser / screen reader combinations. aria-labelledby="calendar info" ,这将确保所有浏览器/屏幕阅读器组合的阅读顺序一致。

Although they would (should) be announced the same from your given example, this is assuming that you hide the SVG from screen readers with aria-hidden="true" .尽管它们会(应该)从您给定的示例中宣布相同,但这是假设您使用aria-hidden="true"屏幕阅读器隐藏了 SVG。 It also assumes that the <div> you added is indeed empty (and not just a placeholder).它还假定您添加的<div>确实是空的(而不仅仅是占位符)。

As an aside make sure you also add focusable="false" to your SVG to account for Internet Explorer users (otherwise they can focus the SVG). focusable="false"确保您还将focusable="false"添加到您的 SVG 以考虑 Internet Explorer 用户(否则他们可以聚焦 SVG)。 Nothing to do with the announcement issue in this question just a good practice.与此问题中的公告问题无关,只是一个很好的做法。

I would suggest your second example should be marked up as follows to save a lot of hassle and to allow the SVG to be part of the document if you wish:-我建议你的第二个例子应该标记如下,以节省很多麻烦,如果你愿意,允许 SVG 成为文档的一部分:-

<div role="application" aria-labelledby="calendar info">
    <h1 id="calendar">Calendar</h1>
    <div>
        <svg focusable="false" aria-hidden="true"/>
        <div></div>
        <div id="info">
          <p>This calendar shows the game schedule for the Boston Red Sox.</p>
        </div>
    </div>
    <div role="grid">
        ...
    </div>
</div>

Final thought最后的想法

Do you really need the <h1 id="calendar" to be read out at all?您真的需要读取<h1 id="calendar"吗? Your description says "This calendar ` at which point stating "Calendar" before is redundant.您的描述说“此日历` 在此之前声明“日历”是多余的。

Always try to avoid repetition.总是尽量避免重复。

If this is the case then you can simplify your example further to just have aria-labelledby="info" .如果是这种情况,那么您可以进一步简化您的示例,只需使用aria-labelledby="info"

Also one last observation role="application" is something that should be used sparingly as it causes all keyboard events to skip the screen reader and go straight to your application.还有最后一个观察role="application"应该谨慎使用,因为它会导致所有键盘事件跳过屏幕阅读器并直接进入您的应用程序。 Be very careful using this as in most circumstances it is not needed and can cause a lot of accessibility headaches.使用它时要非常小心,因为在大多数情况下它是不需要的,并且会导致很多可访问性问题。 Here is a brief article that explains a bit more about the pros and cons of the role. 这是一篇简短的文章,详细解释了该角色的优缺点。

If you remove role="application" then the aria-labelledby may not work on a static div so replace it with an appropriate role.如果您删除role="application"aria-labelledby可能无法在静态 div 上工作,因此请将其替换为适当的角色。

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

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