简体   繁体   English

区分鼠标“单击”和屏幕阅读器“按”

[英]Differentiate between mouse “click” and screen reader “Press”

I'm make an accessible website menu and would like to differentiate between a mouse "Click" and a VoiceOver "Press" to open a submenu. 我正在制作一个可访问的网站菜单,并希望区分鼠标“单击”和VoiceOver“按”以打开子菜单。 When I console.log the event the mouse event gets triggered on the VoiceOver "Press" instead of a keyboard event. 当我console.log事件时,鼠标事件是在VoiceOver“按”而不是键盘事件上触发的。

Is there a way to tell the difference? 有没有办法分辨出差异?

Currently the menu is mouse hover based and I have prevented Click events from toggling the sub menu. 当前,该菜单基于鼠标悬停,并且我阻止了Click事件切换子菜单。 I would however like keyboard only users to be able to open the submenus with screen readers which instruct the user to use command + option + spacebar for a PRESS which triggers a mouse event "click"... 但是,我希望只有键盘的用户能够使用屏幕阅读器打开子菜单,该屏幕阅读器指示用户使用命令+选项+空格键进行PRESS,从而触发鼠标事件“单击”。

One solution I'm working on now is to only disable click events when hover is active... 我现在正在研究的一种解决方案是仅在悬停处于活动状态时才禁用点击事件...

Update: 更新:

Goal: To trigger a mega menu popup for people who can see and link to a page displaying the mega menu links for people who cant. 目标:为可以看到并链接到显示无法打开的人的超级菜单链接的页面的用户触发超级菜单弹出窗口。 From my research, mega menus, even if coded beautifully are a pain for the visually impaired. 根据我的研究,即使菜单编码精美,对于视觉障碍者来说也是一种痛苦。 Recognizing that a menu has expanding is not intuitive even if aria can tell that the menu item is expandable is does not seem to notify when it is expanded. 即使aria可以告知菜单项是可扩展的,也无法识别菜单已扩展,这似乎并没有在扩展时通知。 I thought it would be a better experience for the user navigate to a new page and skip to the content of mega menu links. 我认为对于用户来说,导航到新页面并跳至大型菜单链接的内容会是更好的体验。

Solution: I was able to successfully and independently target keyboard ENTER clicks VoiceOver/screenreader clicks and mouse clicks by using a collection of event listeners. 解决方案:通过使用事件侦听器集合,我能够成功且独立地定位键盘ENTER单击VoiceOver / screenreader单击和鼠标单击。

On mousein to the menu item I set a preventClick flag and on mouseout I remove the flag so that clicking the menu item did not follow the link and only opened the submenu. 在将鼠标移到菜单项上时,我设置了preventClick标志,在鼠标移开时,我删除了该标志,以便单击菜单项时不跟随链接,而仅打开子菜单。

On keydown I check if the "enter" key was pressed. 在按下键盘时,我检查是否按下了“输入”键。 If so I show the submenu and prevent the link from being the followed so that user and tab through the mega menu items. 如果是这样,我将显示该子菜单,并阻止该链接被跟随,以便用户和制表符浏览大型菜单项。

That leaves the screen reader click to follow the link to page dedicated to showing the mega submenu. 屏幕阅读器仅需单击以跟随指向专门显示超级子菜单页面的链接。

Alternatively, for screenreaders, I could open the submenu and send the keyboard focus to the first element of the submenu. 另外,对于屏幕阅读器,我可以打开子菜单并将键盘焦点发送到子菜单的第一个元素。 Not sure if this would be more intuitive for the user. 不知道这对于用户而言是否更直观。

Review: Let me know if you think there are problems with this solution. 评论:如果您认为此解决方案有问题,请告诉我。 So far it works great. 到目前为止,效果很好。 It assumes that people motor control issues and good eyesight use tab+enter to navigate and people who are visually impaired use their screenreaders click equivalent eg. 假设人们的运动控制问题和良好的视力使用tab + enter进行导航,而视障人士则使用其屏幕阅读器单击等效项。 VoiceOvers Command+Option+Space. VoiceOvers Command + Option +空格键。

You will notice from this blog post that it is not possible to naiively differentiate between a mouse user and a screen reader user 您将从此博客文章中注意到,不可能天真地区分鼠标用户和屏幕阅读器用户

http://unobfuscated.blogspot.com/2013/05/event-handlers-and-screen-readers.html http://unobfuscated.blogspot.com/2013/05/event-handlers-and-screen-readers.html

Even if it was possible, attempting to do so is considered a violation of privacy because it is tantamount to the user identifying themselves as disabled. 即使可能,尝试这样做也被视为侵犯隐私,因为这等于用户将自己标识为已禁用。 There should not be any reason to want to do this - what is your use case? 应该没有任何理由要这样做-您的用例是什么?

Update 更新

Your solution will work everywhere except touch devices, where hover does not exist, however that being said, you are going to too much trouble. 您的解决方案将可以在除不存在悬停功能的触摸设备之外的所有地方使用,但是,话虽这么说,您会遇到很多麻烦。 As long as you mark up the mega menu semantically, the blind user will have no problem navigating it. 只要您在语义上标记了大型菜单,盲人用户就可以毫无问题地浏览它。

Take a look at https://www.capitalone.com/ for a reasonably accessible mega-menu implementation. 请访问https://www.capitalone.com/ ,以获取可合理访问的大型菜单实施。

Your best shot is to override accessibilityPerformAction on the menu item, handle the NSAccessibilityPressAction, and then pass to super's implementation to handle things as it would as usual without you overriding anything. 最好的选择是覆盖菜单项上的accessibilityPerformAction,处理NSAccessibilityPressAction,然后传递给super的实现以照常处理事情,而无需覆盖任何内容。 I haven't tried this yet, but I think it has a good chance of working. 我还没有尝试过,但是我认为它很有可能工作。 The point is accessibilityPerformAction gets invoked by VoiceOver (more specifically by AppKit's accessibility support on request from VoiceOver), so this way you know that some assistive technology (eg VoiceOver) requested opening the menu, not mouse. 关键是accessibilityPerformAction由VoiceOver调用(更具体地讲,是应VoiceOver的要求由AppKit的辅助功能支持)调用的,因此您可以通过这种方式知道某些辅助技术(例如VoiceOver)要求打开菜单,而不是鼠标。

Out of curiosity, I am still wondering why you want to differentiate between the 2 cases, what different behavior you would like to achieve. 出于好奇,我仍然想知道为什么要区分这两种情况,您希望实现什么不同的行为。

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

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