简体   繁体   English

可访问性:`tabindex="-1"` 是否意味着该元素对屏幕阅读器不可见(类似于 `aria-hidden="true"`)

[英]Accessibility: does `tabindex="-1"` mean the element is not visible to screenreaders (similar to `aria-hidden="true"`)

I have a webpage where a dialog <section role="dialog"> element opens on-top-of content, causing the elements/content underneath to be inaccessible.我有一个网页,其中一个对话框<section role="dialog">元素在内容顶部打开,导致下面的元素/内容无法访问。

While the dialog is open, all content underneath receives tabindex="-1" to keep the tab-focus within the dialog.当对话框打开时,下面的所有内容都接收tabindex="-1"以保持对话框内的选项卡焦点。

The content underneath also receives a CSS class that blurs the elements, and sets pointer-events to none so the elements are not clickable with a mouse, but these elements are still all present and visible in the DOM (they are NOT set to display: none ).下面的内容也接收一个使元素模糊的 CSS 类,并将pointer-events为 none,这样元素就不能用鼠标点击,但这些元素仍然在 DOM 中全部存在和可见(它们没有设置为display: none )。

Two questions:两个问题:

  1. Do I also need to add aria-hidden="true" to all of these elements too?我还需要为所有这些元素添加aria-hidden="true"吗?
    • I understand the content will no longer be focusable with the tab key, but I'm not sure if the screenreader will still attempt to read the content.我知道内容将不再可用 Tab 键聚焦,但我不确定屏幕阅读器是否仍会尝试阅读内容。
  2. If I am setting aria-hidden="true" on these elements, and later reverting to aria-hidden="false" , will the screenreader pick-up that this change happened?如果我在这些元素上设置aria-hidden="true" ,然后恢复到aria-hidden="false" ,屏幕阅读器会发现发生了这种变化吗?
    • I'm worried that setting aria-hidden="true" means the screenreader will not consider the element again, even if I set it later to aria-hidden="false" .我担心设置aria-hidden="true"意味着屏幕阅读器不会再次考虑该元素,即使我稍后将其设置为aria-hidden="false"
    • Do I need aria-live on the shared parent element (where both the dialog and content exist)?我是否需要在共享父元素上使用aria-live (对话框和内容都存在)?
    • Even with aria-live , would the screenreader consider elements that were previously set to aria-hidden="true" ?即使使用aria-live ,屏幕阅读器是否会考虑先前设置为aria-hidden="true"元素?

Note: the dialog is a form with a submit button.注意:对话框是一个带有提交按钮的表单。 Sometimes it could include a Dismiss button, but not in every case.有时它可能包含一个Dismiss按钮,但并非在所有情况下。 The dialog could be acting as a gate that requires submitting the form to continue.该对话框可以充当需要提交表单才能继续的门。

Accessibility: does tabindex=“-1” mean the element is not visible to screenreaders (similar to aria-hidden=“true” )可访问性: tabindex=“-1”意味着该元素对屏幕阅读器不可见(类似于aria-hidden=“true”

tabindex="-1" means that an item is only focusable programatically. tabindex="-1"表示项目只能以编程方式聚焦。

aria-hidden="true" means that item is completely removed from the accessibility tree. aria-hidden="true"表示该项目已从可访问性树中完全删除。

They may seem the same until you consider that a screen reader user may navigate by <h1> to <h6> (for example).在您考虑屏幕阅读器用户可以通过<h1>导航到<h6> (例如)之前,它们可能看起来相同。 Adding tabindex="-1" makes no difference as a heading is not focusable anyway whereas aria-hidden="true" is essentially the same as saying display: none and means that it cannot be accessed by a screen reader at all.添加tabindex="-1"没有任何区别,因为标题无论如何都不可聚焦,而aria-hidden="true"本质上与说display: none相同,这意味着屏幕阅读器根本无法访问它。

With that in mind the answers to your questions become simple:考虑到这一点,您的问题的答案变得简单:

Do I also need to add aria-hidden="true" to all of these elements too?我还需要为所有这些元素添加 aria-hidden="true" 吗?

Yes you do need to add aria-hidden="true" due to the fact that people may still try to navigate via Headings , Links etc. which aren't focusable anyway but can still be accessed via the virtual cursor.是的,您确实需要添加aria-hidden="true"因为人们可能仍会尝试通过HeadingsLinks等进行导航,这些无论如何都不可聚焦,但仍然可以通过虚拟光标访问。

If I am setting aria-hidden="true" on these elements, and later reverting to aria-hidden="false", will the screen reader pick-up that this change happened?如果我在这些元素上设置 aria-hidden="true",然后又恢复为 aria-hidden="false",屏幕阅读器会发现发生了这种变化吗?

Yes a screen reader will have no problem with this.是的,屏幕阅读器不会有问题。 You do not need anything like aria-live in order to let the screen reader know the changes.您不需要像aria-live这样的任何东西来让屏幕阅读器知道这些更改。 In fact if you added aria-live you would make things less accessible as it would announce every time a change is made to the DOM in that whole section.事实上,如果你添加了aria-live你会让事情变得更难访问,因为它会在整个部分对 DOM 进行每次更改时宣布。

What do you need to consider你需要考虑什么

Managing focus - when you close the dialogue make sure that focus reverts to the button that opened it as that is expected behaviour.管理焦点- 当您关闭对话框时,确保焦点恢复到打开它的按钮,这是预期的行为。 (make sure you do this after you make the parent / item aria-hidden="false" otherwise it may cause unexpected behaviour) (确保您制作父项/项目aria-hidden="false"执行此操作否则可能会导致意外行为)

Esc to close - make sure the Escape key closes the dialogue. Esc 关闭- 确保 Escape 键关闭对话。

How to structure a page for ease如何轻松构建页面

An easy way to achieve all of this (if you are able to restructure everything) is to add all of your dialogues outside of the main content (you may get a warning that 'all items should be contained by landmarks' when running your site through an accessibility checker but ignore that guideline as your dialogue should not be accessible when the page loads anyway).实现所有这一切的一种简单方法(如果您能够重组所有内容)是在主要内容之外添加所有对话(您可能会在运行您的网站时收到“所有项目都应包含在地标中”的警告)可访问性检查器,但忽略该指南,因为无论如何在页面加载时都不应访问您的对话)。

eg例如

<header aria-hidden="false"></header>
<main aria-hidden="false"></main>
<footer aria-hidden="false"></footer>
<section class="dialogue" role="dialogue" aria-hidden="true"></section>

toggles to切换到

<header aria-hidden="true"></header>
<main aria-hidden="true"></main>
<footer aria-hidden="true"></footer>
<section class="dialogue" role="dialogue" aria-hidden="false"></section>

This way you only have 4 items that you need to add / toggle aria-hidden on so maintainability is easy.这样,您只需要添加/切换aria-hidden 4 个项目,因此可维护性很容易。

Also for forward compatibility you may consider using the <dialogue> element同样为了向前兼容,您可以考虑使用<dialogue>元素

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

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