简体   繁体   English

a11y & angularjs - Windows 屏幕阅读器覆盖 keydown 事件

[英]a11y & angularjs - windows screen reader overrides keydown event

im working on making a photo gallery app more accessible.我正在努力使照片库应用程序更易于访问。

the app has a feature of showing expanded view of an image when clicked.该应用程序具有在单击时显示图像扩展视图的功能。

one of the a11y requirements is that when a user focus an image and click enter the expand mode will open and the focus will go inside the expanded view, and will be set on one of the buttons in it. a11y 要求之一是当用户聚焦图像并单击进入扩展模式时,将打开扩展模式,焦点将进入扩展视图内,并将设置在其中的一个按钮上。 it work's fine without screen reader, or with screen reader on mac.它在没有屏幕阅读器的情况下工作正常,或者在 mac 上使用屏幕阅读器。 but on windows when using screen reader it seems that the code that fires is the one that subscribed to the click event and not the keydown event.但是在 Windows 上使用屏幕阅读器时,似乎触发的代码是订阅点击事件而不是 keydown 事件的代码。 because the flag that suppose to be set to true on keydown is false (both events fire the same function but the keydown also add the enterClicked variable set to true).因为假设在 keydown 上设置为 true 的标志是 false (两个事件都触发相同的函数,但 keydown 还添加了设置为 true 的 enterClicked 变量)。

this is the div that hold the image and subscribed to the events:这是保存图像并订阅事件的 div:

    <div 
        tabindex="0" 
        id="{{media.id}}" 
        data-ng-repeat="media in row track by media.id" 
        data-ng-mouseenter="events.toggleVideoPlay(media.type, media.id, media.link, ( rowNummer ) * (row.length) + ($index + 1))" class="imgContainer" 
        ng-keydown="$event.keyCode == 13 ? events.openExpandMode(media.id, true) : null"
        data-ng-click="events.openExpandMode(media.id)"
      >

openExpandMode function: openExpandMode 函数:

$scope.events.openExpandMode = (mediaId, isEnterClicked) => {
const state = {
            isEnterClicked,
            mediasId,
            currentIndex,
            pagination: $scope.mediasPagination,
            settings: {
                isUserName: $scope.settings.user_name_checkbox,
                isTemplate: !$scope.userConnected && !$scope.userConnectedWithOldApi,
                isLikeComments: $scope.settings.like_comments_checkbox,
                isDescriptions: $scope.settings.description_checkbox,
                isComments: $scope.settings.comments_checkbox,
                theme: $scope.settings.expand_theme,
                lang: $translate.use()
            }
        };
localStorageService.set('state', state);
}

expand mode component init:展开模式组件初始化:

const _init = () => {
   if ($scope.isOpenFromEnter) {
                    document.getElementById('nextArrow').setAttribute('data-focus-visible-added', "");
                    document.getElementById('nextArrow').className += ' focus-visible';
                    document.getElementById('nextArrow').focus();
                }
}

is there a way to stop windows screen reader event interception ?有没有办法阻止 Windows 屏幕阅读器事件拦截?

Short answer简答

It's common to send a click event instead of a press enter event.发送点击事件而不是按下回车事件是很常见的。 The best is probably to adapt your code so that click and enter do the same thing, and that either or both event can be sent, because you only have a quite limited influence on which is sent or not and when最好的办法可能是调整您的代码,以便单击和输入做同样的事情,并且可以发送一个或两个事件,因为您对发送或不发送以及何时发送的影响非常有限

Longer answer更长的答案

You haven't indicated which screen reader you were using (Jaws or NVDA), but anyway, it's common for both to send a click event when pressing enter, instead of sending key events.您没有指明您使用的是哪个屏幕阅读器(Jaws 或 NVDA),但无论如何,在按下 Enter 键时发送点击事件而不是发送按键事件是很常见的。

Reasons for that may seem strange and illogical at first, but there are at least two good ones:其原因乍一看似乎很奇怪和不合逻辑,但至少有两个好处:

  • It's certainly as much illogical to have two different things happening when clicking or pressing enter.在单击或按 Enter 时发生两种不同的事情当然是不合逻辑的。 IN all applications since GUI exist, most often, both do the same action (the only exception I can think of right now is multiline or rich text fields).自 GUI 存在以来的所有应用程序中,大多数情况下,两者都执行相同的操作(我现在能想到的唯一例外是多行或富文本字段)。
  • Scren readers existed before web accessibility, and accessibility is still rarely implemented nowadays.屏幕阅读器在 Web 可访问性之前就已经存在,而如今可访问性仍然很少实现。 Sending a click event when pressing enter provide a minimal usability in all the places where designers didn't even thought that the keyboard could be used instead of the mouse.在按下回车键时发送点击事件在所有设计人员甚至不认为可以使用键盘代替鼠标的地方提供最小的可用性。

By the way, screen reader or not, guess which event is sent if you press enter when the focus is on a link or a button?顺便说一句,无论是否使用屏幕阅读器,猜猜当焦点位于链接或按钮上时按下 Enter 会发送哪个事件? Depending on the browser, the answer isn't unanimous as far as I know.根据浏览器的不同,据我所知,答案并不是一致的。 And on the screen reader side, it isn't unanimous either.在屏幕阅读器方面,它也不是一致的。 Some even allow to configure the exact behavior to take, in order to adapt to different more or less unaccessible sites.有些甚至允许配置要采取的确切行为,以适应不同的或多或少无法访问的站点。

is there a way to stop windows screen reader event interception ?有没有办法阻止 Windows 屏幕阅读器事件拦截?

You can stop some form of interception by calling preventDefault in your event listener function, if the click event is generated by the browser.如果单击事件是由浏览器生成的,您可以通过在事件侦听器函数中调用 preventDefault 来停止某种形式的拦截。 By doing so, you can actually do something different on click and on enter.通过这样做,您实际上可以在单击和输入时执行不同的操作。 But ask yourself first if it is really justified.但首先问问自己这是否真的合理。 Think about my first point above.想想我上面的第一点。

However, you can't prevent screen readers from intercepting keyboard events, translate them to something else and send or don't send them to your page.但是,您无法阻止屏幕阅读器拦截键盘事件、将它们转换为其他内容并将它们发送或不发送到您的页面。 There exists the ARIA application mode, but it has several important implications, so you shouldn't use it unless you have true good reasons.存在 ARIA 应用程序模式,但它有几个重要的含义,因此除非您有真正的充分理由,否则不应使用它。

To wrap up, the best is probably to adapt your code so that click and enter do the same thing, and that either or both event can be sent.总结一下,最好的办法可能是调整您的代码,以便单击和输入执行相同的操作,并且可以发送其中一个或两个事件。

role="application"添加到容器div修复了它。

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

相关问题 用于 a11y 合规性的按键事件处理程序 - Keypress event handler for a11y compliance 可访问的表单输入作为按钮 - a11y accessible form inputs as buttons keyDown事件将覆盖粘贴事件 - keyDown event overrides paste event Mathjax无法加载:扩展:[“ [Contrib] /a11y/accessibility-menu.js”] - Mathjax failed to load: extensions: [“[Contrib]/a11y/accessibility-menu.js”] 键盘a11y,用于多级导航菜单,其中按钮作为顶层项目 - Keyboard a11y for a multi-level navigation menu with buttons as top level items Svelte label class 给了我“A11y:表格 label 必须与控件相关联。” - Svelte label class gives me "A11y: A form label must be associated with a control." 为什么需要将对话框模式作为正文的最后一个直接子级放置?[可访问性,a11y] - Why a dialog modal needs to be placed as last direct child of the body?[Accessibility, a11y] msRequestFullscreen 在按键事件 (IE 11) 的情况下不起作用 - msRequestFullscreen not working in case keydown event (IE 11) 如何在按键事件中更改AngularJS中的模型 - How to change model in AngularJS on keydown event 当浏览器已经处于全屏模式时,Chrome会在F11键上按下javascript keydown事件处理程序 - Chrome eats javascript keydown event handler on F11 key press, when browser is already in full screen mode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM