简体   繁体   English

aria role="application" 和制表符

[英]aria role=“application” and tab-trapping

Tab trapping is a fairly well established pattern ( example ). 制表符陷印是一种相当成熟的模式( 示例)。 Typically for the sake of accessibility, it allows keyboard users to navigate inside dropdown menus and modals.通常为了可访问性,它允许键盘用户在下拉菜单和模式中导航。 What's concerning however are the implications for users now that the native functionality of the tab event has been overwritten with a new behavior (looping).然而,令人担忧的是对用户的影响,因为选项卡事件的本机功能已被新行为(循环)覆盖。 This isn't a big deal for sighted users, but it is problematic for users of Assistive Technologies like NVDA and JAWS that critically rely on that native tab functionality.这对于视力正常的用户来说没什么大不了的,但对于像 NVDA 和 JAWS 这样严重依赖原生选项卡功能的辅助技术用户来说,这是有问题的。

WAI-ARIA has a solution for informing Assistive Technologies of when native keyboard functionality has been overwritten in the form of aria-role="application" : WAI-ARIA 有一个解决方案,用于通知 Assistive Technologies 原生键盘功能何时以aria-role="application"的形式被覆盖:

Keyboard interaction is completely under the web author's control and can be anything associated with the particular widget being implemented.键盘交互完全在 web 作者的控制下,可以是与正在实现的特定小部件相关的任何内容。 In a slides application, for example, a widget could be created that uses the arrow keys to position elements on the slide, and uses audio feedback via an ARIA live region to communicate the position and overlap status with other objects.例如,在幻灯片应用程序中,可以创建一个小部件,该小部件使用箭头键指向幻灯片上的 position 元素,并通过 ARIA 活动区域使用音频反馈来传达 position 和与其他对象的重叠状态。 Focus is being managed via aria-activedescendant.通过 aria-activedescendant 管理焦点。

The tab, Space and Enter keys, as well as Escape, must be handled by the application.选项卡、Space 和 Enter 键以及 Escape 必须由应用程序处理。 The one exception is if focus is set to a standard widget inside the application that supports keyboard navigation from the browser, for example an input element.一个例外是,如果焦点设置为应用程序内支持从浏览器进行键盘导航的标准小部件,例如输入元素。

This would imply that any component that employs tab-trapping should necessary have a role="application" , always .这意味着任何使用 tab-trapping 的组件都必须有一个role="application"always

However I don't believe this common practice.但是我不相信这种常见的做法。 Sites like Target.com for example (that use tab trapping on their dropdown menu) categorize it as a list, as seen here in the website Accessibility Tree:例如,像Target.com 之类的网站(在其下拉菜单中使用制表符陷印)将其归类为列表,如网站 Accessibility Tree 中所示: 在此处输入图像描述

I'd appreciate any experienced perspectives on this.我将不胜感激任何有经验的观点。 Am I interpreting ARIA correctly here?我在这里正确解释 ARIA 吗? Should components that employ tab-trapping always be decorated with role="application" ?使用 tab-trapping 的组件应该总是role="application"装饰吗?

Short Answer简短的回答

You do not need to add role="application" provided you set the menus up as modal dialogs.如果您将菜单设置为模式对话框,则无需添加role="application" With other patterns it may be applicable (highly unlikely, role="application" is a very specialised role) but at that point you probably implemented the wrong pattern in the first place.对于其他模式,它可能适用(极不可能, role="application"是一个非常专业的角色)但那时您可能首先实现了错误的模式。

Longer Answer更长的答案

The loop pattern is fine as long as implemented correctly (and target.com did a pretty good job)只要正确实施,循环模式就很好(并且 target.com 做得很好)

There is nothing wrong with this pattern as long as it is implemented correctly (which target.com seems to surprisingly do a quite good job of, just a few things they could do better).只要正确实施此模式就没有任何问题(target.com 似乎出人意料地做得相当好,只是他们可以做得更好的几件事)。

Using 'target' as an example, you will notice that when you click on 'categories' for example the revealed menu actually gets treated like a modal dialog.以“目标”为例,您会注意到,例如,当您单击“类别”时,显示的菜单实际上被视为模态对话框。

It has role="dialog" and the 'button' that opens it has aria-expanded .它有role="dialog"和打开它的 'button' 有aria-expanded

They also trap tab focus within this modal and provide a 'close' button that appears at the bottom of the list if you are using the tab key.如果您使用 tab 键,它们还会在此模式中捕获选项卡焦点,并提供显示在列表底部的“关闭”按钮。

All good so far, nothing wrong with looping within a modal dialog as that is expected behaviour.到目前为止一切都很好,在模态对话框中循环没有错,因为这是预期的行为。

They also get a few other things right, once the 'dialog' is open you cannot access any other content.他们还做对了一些其他事情,一旦“对话框”打开,您就无法访问任何其他内容。 For example in a screen reader you may press the keys 1-6 to find the next heading levels, you cannot do this while the menu is open as they apply aria-hidden="true" to everything outside of the menu modal (a true modal trap).例如,在屏幕阅读器中,您可以按 1-6 键来查找下一个标题级别,当菜单打开时您不能这样做,因为它们将aria-hidden="true"应用于菜单模式之外的所有内容(真正的模态陷阱)。

Also you can close the menu modal and focus is returned to the menu item that opened it in the first place, so they manage focus correctly too.您也可以关闭菜单模式并将焦点返回到首先打开它的菜单项,因此它们也可以正确管理焦点。

Finally you can close the menu modal with the Escape key, which is also expected behaviour.最后,您可以使用Escape键关闭菜单模式,这也是预期的行为。

So if you wanted to follow this pattern for your menus I would say go for it, they are accessible as they are and a screen reader user would not struggle using them.因此,如果您想在菜单中遵循这种模式,我会说 go,它们可以按原样访问,并且屏幕阅读器用户不会很难使用它们。

What can we do better than target.com我们能做的比target.com更好吗

Target got the basics right, they are just missing a few key steps. Target 掌握了正确的基础知识,他们只是缺少几个关键步骤。

The 'button' that opens the menu should have the aria-controls attribute just to link that together properly.打开菜单的“按钮”应该具有aria-controls属性,以便正确地将它们链接在一起。

The menu items within the menu dialogs should all have <nav> elements around the <ul> (although arguably as these modals should only be accessible via the menu button this association is implied and this is a minor point).菜单对话框中的菜单项都应该在<ul>周围有<nav>元素(尽管可以说这些模式应该只能通过菜单按钮访问,这种关联是隐含的,这是一个小问题)。

The arrow sprites they use have focusable="false" which is good but they didn't add role="presentation" or better yet aria-hidden="true" so they do get announced if your screen reader is set to verbose.他们使用的箭头精灵有focusable="false"这很好,但他们没有添加role="presentation"或者更好的是aria-hidden="true"所以如果你的屏幕阅读器设置为详细,它们会被宣布。 ( aria-hidden="true" is preferable as support is better). aria-hidden="true"更好,因为支持更好)。

The menus themselves should not really be multi-layered.菜单本身不应该是多层的。 ie if you click 'main menu' at the top of the list it then becomes confusing as to where you are, am I still within the modal dialog?即,如果您单击列表顶部的“主菜单”,那么您的位置就会变得混乱,我是否仍在模态对话框中? Additionally this is implemented in a way where it does not announce the first item in the 'main menu' list once you follow the link (timing issue maybe?) so it is disorientating.此外,这是以一种方式实现的,一旦您点击链接(可能是时间问题?),它就不会宣布“主菜单”列表中的第一项,因此它会让人迷失方向。 This is the biggest problem with their implementation.这是他们实施的最大问题。

There are other things but you get the idea, if your menu is just a single list per 'drop down' (modal), the way this is implemented is perfectly acceptable and usable and better than a lot of menu implementations I have seen.还有其他事情,但你明白了,如果你的菜单只是每个“下拉”(模态)的一个列表,那么这种实现方式是完全可以接受和可用的,并且比我见过的许多菜单实现更好。

So should I use role="application"所以我应该使用role="application"

No.不。

Seriously, you will probably never need to use this during your career and it's use can break a lot of accessibility.说真的,你可能永远不需要在你的职业生涯中使用它,它的使用会破坏很多可访问性。

Oh you want more detail?哦,你想要更多的细节? No problem!没问题!

No you do not need to use role="application" here, in fact you would introduce a lot more accessibility issues doing so.不,您不需要在这里使用role="application" ,实际上这样做会引入更多可访问性问题。

role="application" implies that all the controls are custom and that you should disregard the standard website controls. role="application"意味着所有控件都是自定义的,您应该忽略标准网站控件。 (you are basically telling the user / screen reader 'treat this like a desktop application where shortcut keys will be explained via the menus etc.' and 'expect some strange behaviour that is not associated with websites, do not rely on your normal keyboard shortcuts as they probably won't work') (您基本上是在告诉用户/屏幕阅读器“将其视为桌面应用程序,其中将通过菜单等解释快捷键”和“期望一些与网站无关的奇怪行为,不要依赖您的正常键盘快捷键因为他们可能不会工作')

As this follows a standard web pattern (trapping focus within a modal) adding role="application" would actually confuse people.由于这遵循标准 web 模式(在模态中捕获焦点),因此添加role="application"实际上会使人们感到困惑。

You mentioned about the Tab looping, but within the list it functions as expected (pressing the down arrow at the end of the list does not loop) so the Tab looping only occurs within the modal.您提到了Tab循环,但在列表中它按预期运行(按列表末尾的向下箭头不会循环),因此Tab循环仅发生在模态中。

I think the following quote for the page I linked on role="application" summarises the important information.我认为我在role="application"上链接的页面的以下引用总结了重要信息。 I have added bold for emphasis on the key points that are applicable to your question and added comments after if appropriate.我添加了粗体以强调适用于您的问题的关键点,并在适当的情况下添加评论。

The application role indicates to assistive technologies that this part of the web content contains elements that do not conform to any other known HTML element or WAI-ARIA widget .应用程序角色向辅助技术表明 web 内容的这一部分包含不符合任何其他已知 HTML 元素或 WAI-ARIA 小部件的元素 Any sort of special interpretation of HTML structures and widgets should be suspended, and control should be completely handed over to the browser and web application to handle mouse, keyboard, or touch interaction.应暂停对 HTML 结构和小部件的任何特殊解释,控制权应完全移交给浏览器和 web 应用程序以处理鼠标、键盘或触摸交互。

In this mode, the web author is completely responsible for handling any and all keyboard input, focus management, and other interactions and cannot assume assistive technologies would do any processing on their end .在这种模式下, web 作者完全负责处理任何和所有键盘输入、焦点管理和其他交互,并且不能假设辅助技术最终会进行任何处理

So basically if you added role="application" you would then not get the native behaviour of any element, this would introduce a lot of work, (in practice most screen readers will still allow basic functionality, but they do this because people misuse role="application" )所以基本上如果你添加了role="application"你就不会得到任何元素的本机行为,这会引入很多工作,(实际上大多数屏幕阅读器仍然允许基本功能,但他们这样做是因为人们滥用role="application" )

If the web application encompassed by the application role contains parts that should be treated like normal web content, a role of document or article should be used .如果应用程序角色包含的 web 应用程序包含应像正常 web 内容一样处理的部分,则应使用文档或文章的角色

So you would have to add role="article" or role="document" to the lists, the close buttons etc. Basically the whole thing would have role="article" anyway (as that would be the most appropriate role).因此,您必须将role="article"role="document"添加到列表、关闭按钮等。基本上整个事情都会有role="article" (因为那将是最合适的角色)。

Unless you are building very complex software, role="application" should not be used.除非您正在构建非常复杂的软件,否则不应使用role="application"

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

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