[英]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 屏幕阅读器事件拦截?
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最好的办法可能是调整您的代码,以便单击和输入做同样的事情,并且可以发送一个或两个事件,因为您对发送或不发送以及何时发送的影响非常有限
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:其原因乍一看似乎很奇怪和不合逻辑,但至少有两个好处:
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.