简体   繁体   English

jquery-ui 选项卡“不得嵌套交互式控件”

[英]jquery-ui tab "Interactive controls must not be nested"

I use jquery-ui tabs.我使用 jquery-ui 选项卡。 Sample code:示例代码:

<ul role="tablist">
 <li role="tab"><a class="label" href="#tabs-1" aria-label="Description tab">Description</a></li>
 <li role="tab"><a class="label" href="#tabs-2" aria-label="Reviews tab">Reviews</a></li>
 <li role="tab"><a class="label" href="#tabs-3" aria-label="Credits tab">Credits</a></li>
 <li role="tab"><a class="label" href="#tabs-4" aria-label="Cataloging tab">Cataloging</a></li>
</ul>

The axe-core DevTools accessibility checker flags a "serious" problem with this code: "Interactive controls must not be nested", with the explanation "Interactive control elements must not have focusable descendants" and referencing guideline WCAG 4.1.2. axe-core DevTools 可访问性检查器将此代码标记为“严重”问题:“不得嵌套交互式控件”,并说明“交互式控件元素不得具有可聚焦的后代”并参考 WCAG 4.1.2 指南。

The problem, as I understand it, is that there is a link inside the listitem.据我了解,问题在于列表项中有一个链接。 From a Github discussion for axe-core ( https://github.com/dequelabs/axe-core/issues/601 ), the clickable link within the list item causes issues with screen readers.从关于 axe-core ( https://github.com/dequelabs/axe-core/issues/601 ) 的 Github 讨论中,列表项中的可单击链接会导致屏幕阅读器出现问题。

But this seems like a standard use of the jquery-ui tab widget.但这似乎是 jquery-ui 选项卡小部件的标准用法。 Is the jquery-ui tab widget just not accessible? jquery-ui 选项卡小部件是否无法访问? Or is axeTools flagging a non-issue?或者 axeTools 是否标记了非问题?

The items within <ul role="tablist"> will have tabindex="0" etc. added to them in order to make them focusable (the actual li , not the link) and then the anchor should have tabindex="-1" added to it. <ul role="tablist">的项目将添加tabindex="0"等以使它们具有焦点(实际li ,而不是链接),然后锚点应该有tabindex="-1"添加到它。

The idea is that the link is a fallback for if JS fails, this is why it is included in the first place and isn't just plain text.这个想法是,如果 JS 失败,链接是一个后备,这就是为什么它首先被包含,而不仅仅是纯文本。

However this does indeed cause nesting of interactive elements as you now have tabindex="0" on the list item (making it "interactive" / focusable) and then a link within it.但是,这确实会导致交互元素的嵌套,因为您现在在列表项上有tabindex="0" (使其“交互”/可聚焦),然后是其中的链接。

They add tabindex="-1" to the link to remove it from the focus order, but some screen reader / browser combos will still pick this link up and this is why it is flagged.他们将tabindex="-1"添加到链接以将其从焦点顺序中删除,但某些屏幕阅读器/浏览器组合仍会选择此链接,这就是它被标记的原因。

So there is a workaround but you will need to implement it yourself.所以有一个解决方法,但你需要自己实现它。

First, add role="presentation none" to the link:首先,将role="presentation none"添加到链接中:

<li role="tab"><a class="label" href="#tabs-1" role="presentation none">Description</a></li>

What this does is signal that this anchor should be treated like a <div> or a <span> as far as assistive technology is concerned (it removes all semantic meaning).这样做的信号是,就辅助技术而言,这个锚点应该被视为<div><span> (它删除了所有语义含义)。

Secondly, (but you would have to check it works with jQuery-UI) would be to remove the href attribute from the link via JS (so it is only removed once the Tab component has initialised).其次,(但您必须检查它是否适用于 jQuery-UI)是通过 JS从链接中删除href属性(因此只有在 Tab 组件初始化后才会删除它)。

You should end up with the following if you inspect the elements after doing this (ignoring any classes added etc.):如果您在执行此操作后检查元素(忽略添加的任何类等),您应该最终得到以下结果:

<li role="tab"><a class="label" role="presentation none">Description</a></li>

This will stop it being a focusable item if JS works and loads correctly, but will fall back gracefully if JS fails to load.如果 JS 工作并正确加载,这将阻止它成为可聚焦的项目,但如果 JS 加载失败,它将优雅地退回。

Also notice I removed your aria-label as the fact you are using a role="tab" already tells a screen reader that it is a tab so your label was not needed.另请注意,我删除了您的aria-label ,因为您使用role="tab"的事实已经告诉屏幕阅读器它是一个选项卡,因此不需要您的 label。

So in summary:总而言之:

  • add role="presentation none" to the links within the <li>role="presentation none"添加到<li>中的链接
  • remove the href attribute from the links via JavaScript.通过 JavaScript 从链接中删除href属性。
  • remove the aria-label (not related to the problem)删除aria-label (与问题无关)

This should make the tabs as accessible as possible within jQuery-UI, but there may be other problems with it so I can't say whether it is accessible or not!这应该使 jQuery-UI 中的选项卡尽可能可访问,但它可能存在其他问题,所以我不能说它是否可以访问!

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

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