如何在已关闭的模态链接之间切换标签?#辅助功能

huangapple go评论85阅读模式
英文:

How to tab past closed modal links? #a11y

问题

一般无障碍性问题。我正在寻找一般的解决方法,但也注意到这是一个React应用程序,因此状态性是需要考虑的因素。

请参考以下代码示例,其中包含一组操作,这些操作打开相应的模态框。理想情况下,您应该能够按顺序通过操作列表进行制表 - 但由于模态框内包含链接,制表体验并不理想。基本上,您要按下'操作1',然后制表6次才能到达'操作2',因为模态框中包含5个链接。

<li class="list__item">
   <!-- 模态框触发器 -->
   <a href="#" class="modal">操作1</a>

   <!-- 包含链接的模态框 -->
   <aside class="item__modal modal" id="modal-interview-1">
      <a href="#>示例1</a>
      <a href="#>示例2</a>
      <a href="#>示例3</a>
      <a href="#>示例4</a>
      <a href="#>示例5</a>
   </aside>
</li>
<li class="list__item">
   <!-- 模态框触发器 -->
   <a href="#" class="modal">操作2</a>

   <!-- 包含链接的模态框 -->
   <aside class="item__modal modal" id="modal-interview-2">
      <a href="#>示例1</a>
      <a href="#>示例2</a>
      <a href="#>示例3</a>
      <a href="#>示例4</a>
      <a href="#>示例5</a>
   </aside>
</li>

处理禁用选项卡时如何隐藏锚标签以及如何使其不可访问以及如何使其在屏幕阅读时不可访问的最佳方法是什么?我尝试将disabled添加到锚标签,并在模态框不活动时添加aria-focusable="false",但这不会产生跳过链接的所需效果。谢谢您在此问题上的帮助。

英文:

General accessibility question here. I'm looking for general approach, but will also note that this is in a React app so statefulness is a consideration.

Take the following code example of a list of actions, which open corresponding modals. Ideally, you would be able to tab through the list of actions in sequence - but because the modals have links inside, the tabbing experience is not ideal. Basically, you hit 'action 1' and then tab 6 more times before hitting 'action 2' due to the 5 links contained in the modal.

<li class="list__item">
   <!-- modal trigger -->
   <a href="#" class="modal">Action 1</a>

   <!-- modal containing links -->
   <aside class="item__modal modal" id="modal-interview-1">
      <a href="#>Sample 1</a>
      <a href="#>Sample 2</a>
      <a href="#>Sample 3</a>
      <a href="#>Sample 4</a>
      <a href="#>Sample 5</a>
   </aside>
</li>
<li class="list__item">
   <!-- modal trigger -->
   <a href="#" class="modal">Action 2</a>

   <!-- modal containing links -->
   <aside class="item__modal modal" id="modal-interview-2">
      <a href="#>Sample 1</a>
      <a href="#>Sample 2</a>
      <a href="#>Sample 3</a>
      <a href="#>Sample 4</a>
      <a href="#>Sample 5</a>
   </aside>
</li>

The question on approach what is the best way to handle hiding the anchor tags from the DOM, or at least from tabbing and screen reading, when a tab is disabled? I've tried adding disabled to the anchors, and adding an aria-focusable="false" to the modal when it's inactive... but it's not giving me the desired effect of skipping the links.

Thanks for your help with this issue.

答案1

得分: 1

我是inert属性的忠实支持者。目前它仍处于草案阶段(我听说在Chrome中可以通过标志启用它)。您可以填充该属性

本质上,您会将inert属性设置为元素被隐藏时,所有技术都会表现得好像链接不存在。在填充页面上有一个非常好的演示,可以更好地说明这个概念。我认为这可以解决您的问题。

英文:

I'm a big fan of the inert attribute. It's currently still in draft (I've heard that it's available in Chrome behind a flag). You can polyfill the attribute

In essence, you'd set inert as the element is hidden and all technologies would act as though the links aren't there. There's a really good demo on the polyfill page that will better illustrate the idea. I think it would solve your issue.

答案2

得分: 1

aria-focusable="false"仅供屏幕阅读器使用,支持不太好,这就是你遇到问题的原因。

你有几个可靠的选项:-

  1. item__modal modal上使用display: none,然后当你添加modal--active时,将其覆盖为display: block(或其他,如flex等)- 在父元素上使用display: none是可靠的,并且始终会使其子元素无法聚焦。这将始终有效,是最佳选项。

  2. 在每个链接上设置tabindex="-1"(不幸的是,你不能将其添加到父元素,因为它仍然可以在某些屏幕阅读器上被覆盖),并在模态框打开时将其更改为tabindex="0"

<aside class="item__modal modal modal--active" id="modal-interview-1">
   <a href="#" tabindex="-1">示例1</a>
   <a href="#" tabindex="-1">示例2</a>
   <a href="#" tabindex="-1">示例3</a>
   <a href="#" tabindex="-1">示例4</a>
   <a href="#" tabindex="-1">示例5</a>
</aside>

这将在所有浏览器中始终保持一致。

不仅仅是Tab键

以上是唯一可靠的选项,因为屏幕阅读器用户很少使用tab键进行导航。

例如,NVDA用户将使用1-6来按标题级别(H1 - H6)导航,使用K来按链接导航以了解页面。

最后的选项(不推荐)

你可以拦截Tab键按下并管理焦点,但由于相同原因,你需要为每个链接添加aria-hidden="true"(在模态框激活时更改为aria-hidden="false")。

这最后的选项至少为你提供了使用opacity: 0来隐藏项目等的选项,如果你真的需要的话。

英文:

aria-focusable=&quot;false&quot; is only for screen readers and not well supported, which is why you are struggling with that.

You have a couple of robust options:-

  1. Use display: none on the item__modal modal and then when you add the modal--active override it to display: block (or whatever, flex etc.) - display: none on a parent element is robust and will always make it's children unfocusable. This will always work and is the best option.

  2. Set a tabindex=&quot;-1" on each link (sadly you can't add it to the parent as it can still get overridden on some screen readers) and change it to tabindex=&quot;0&quot; when the modal opens.

     &lt;aside class=&quot;item__modal modal modal--active&quot; id=&quot;modal-interview-1&quot;&gt;
        &lt;a href=&quot;#&quot; tabindex=&quot;-1&quot;&gt;Sample 1&lt;/a&gt;
        &lt;a href=&quot;#&quot; tabindex=&quot;-1&quot;&gt;Sample 2&lt;/a&gt;
        &lt;a href=&quot;#&quot; tabindex=&quot;-1&quot;&gt;Sample 3&lt;/a&gt;
        &lt;a href=&quot;#&quot; tabindex=&quot;-1&quot;&gt;Sample 4&lt;/a&gt;
        &lt;a href=&quot;#&quot; tabindex=&quot;-1&quot;&gt;Sample 5&lt;/a&gt;
     &lt;/aside&gt;
    

This will work consistently across all browsers.

##It isn't just the tab key

The reason the above are the only robust options is because screen reader users rarely navigate by the tab key.

For example a NVDA user will use 1-6 to navigate by heading levels (H1 - H6) and K to navigate by links to get a feel for the page.

##final option (not recommended)

You could intercept the tab key presses and manage focus, but you would need to then add aria-hidden=&quot;true&quot; to each of the links for the same reason (and change it to aria-hidden=&quot;false&quot; when the modal is active.

This last option does at least afford you the option of using opacity: 0 to hide the items etc. if you really need to.

huangapple
  • 本文由 发表于 2020年1月4日 00:55:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/59582380.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定