NVDA / FOCUS /可访问性问题
我们正在构建自定义下拉组件,并使用层次组成的复选框选择。每个层次结构均使用标准Bootstrap 3手风琴代码显示/隐藏,该代码很好地处理屏幕读取器(这是一个Drupal站点,因此Bootstrap 3是支持的版本)。
我们拥有控制上/下/home/home/end键的代码,该密钥在运行NVDA时完全无法触发。单击向下箭头应该带您进入下一个可见的复选框。主钥匙将您带到第一个。最终键将您进入最后一个。
当NVDA不运行时,所有这些都可以正常工作。跑步时,主/端钥匙什么都不做。向上/下箭头像Tab/shift-tab这样的作用,因此它们不会转到下一个复选框;他们转到下一个可表的元素。
这在所有浏览器中都在发生。
有人知道如何解决这个问题吗?
小提琴:
$(document).ready(function(){
$('.region_of_delivery_checkbox').keyup(function(e){
var code = (e.keyCode ? e.keyCode : e.which);
var tabables = $(".region_of_delivery_checkbox:visible");
var index = tabables.index(this);
console.log(`checkbox and tabables.length = ${tabables.length} and tabables.index(this) is: ${tabables.index(this)}`);
if(code == 40) {
console.log("40");
tabables.eq(index + 1).focus();
console.log(`tabables.eq(index + 1) is: ${index}`);
} else if(code == 38) {
console.log("38");
tabables.eq(index - 1).focus();
} else if(code == 35) {
console.log("35");
tabables.eq(tabables.length - 1).focus();
} else if(code == 36) {
console.log("36");
tabables.eq(0).focus();
}
});
});
We are building custom dropdown components with a hierarchical selection of checkboxes. Each hierarchy is shown/hidden using standard bootstrap 3 accordion code which handles screen readers very well (this is a Drupal site so bootstrap 3 is the version supported).
We have code controlling the up/down/home/end keys which completely fails to trigger when NVDA is running. Clicking the down arrow is supposed to take you to the next visible checkbox. The home key takes you to the first. The end key takes you to the last.
All this works fine when NVDA is not running. When running, the home/end keys do nothing. The up/down arrow act like tab/shift-tab so they don't go to the next checkbox; they go to the next tabable element.
This is happening in all browsers.
Does anyone know how to fix this?
Fiddle:
https://jsfiddle.net/1pya0bm3/1/
$(document).ready(function(){
$('.region_of_delivery_checkbox').keyup(function(e){
var code = (e.keyCode ? e.keyCode : e.which);
var tabables = $(".region_of_delivery_checkbox:visible");
var index = tabables.index(this);
console.log(`checkbox and tabables.length = ${tabables.length} and tabables.index(this) is: ${tabables.index(this)}`);
if(code == 40) {
console.log("40");
tabables.eq(index + 1).focus();
console.log(`tabables.eq(index + 1) is: ${index}`);
} else if(code == 38) {
console.log("38");
tabables.eq(index - 1).focus();
} else if(code == 35) {
console.log("35");
tabables.eq(tabables.length - 1).focus();
} else if(code == 36) {
console.log("36");
tabables.eq(0).focus();
}
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是标准的屏幕阅读器行为。下拉次数打开时,您仍处于屏幕读取器“浏览”模式中,并且将箭头键发送到屏幕读取器以进行解释,而不是浏览器。您可以通过按 ins + space 来切换“浏览”模式。切换模式时,您会听到声音通知。然后,您可以使用箭头键或主页/结束,事件将发送到浏览器,您将获得预期的行为。
但是主要的问题是,当您的下拉小部件接收到焦点时,您处于“浏览”模式。正确编码的下拉列表将自动将屏幕读取器从浏览模式中切换出来,以便箭头键可以按照您的预期工作。
如果您测试了此W3.org示例,则 https://www.w.org/wai/aria/apg/example-index/combobox/combobox/combobox-select-only.html ,当您 tab> tab 时, '将听到浏览器切换模式的可听见通知。按下 ins + space 时,您听到的声音相同。您的小部件应该做同样的事情。
您会注意到该示例使用
roun =“ combobox”
,因为您的代码没有。那是主要问题。That's standard screen reader behavior. When your dropdown opens, you're still in screen reader "browse" mode and the arrow keys are sent to the screen reader for interpretation rather than to the browser. You can switch out of "browse" mode by pressing Ins+space. You'll hear an audible notification when it switches mode. You can then use the arrow keys or home/end and the events will be sent to the browser and you'll get your expected behavior.
But the main problem is that you are in "browse" mode when your dropdown widget receives focus. A correctly coded dropdown list will automatically switch the screen reader out of browse mode so that the arrow keys will work as you expect.
If you test this W3.org example, https://www.w3.org/WAI/ARIA/apg/example-index/combobox/combobox-select-only.html, when you tab to the combobox, you'll hear the audible notification of the browser switching modes. The same sound you hear when you pressed Ins+space. Your widget should do the same.
You'll notice the example uses
role="combobox"
where as your code does not. That's the main problem.将角色=“应用”添加到表单中。 NVDA将自动切换到焦点模式,并且代码将正常工作。
Add role="application" to the form. NVDA will automatically switch to focus mode and the code will work fine.