【发布时间】:2019-05-31 16:52:00
【问题描述】:
我正在努力使我们的手风琴可以通过 aria-expanded 等 aria 标签访问。当单击手风琴触发器标题或按下键盘上的“返回”按钮时,我正确地获得了 aria-expanded 更改的值。出于某种原因,虽然我用来测试的 ChromeVox 最初只会说“按钮折叠”,但一旦点击后值发生变化,就不会说“按钮展开”。
我查看了其他网站上的示例,例如 https://www.w3.org/TR/wai-aria-practices/examples/accordion/accordion.html,ChromeVox 可以正确读取 aria-expanded 的两种状态,所以我认为这是我的代码结构导致 ChromeVox 无法发布“展开”状态。
这是一个手风琴部分的示例:
<div class="accordion-section">
<button tabIndex="0" id="rules_list" class="accordion" aria-expanded="false" aria-controls="sectRules">
<span class="title">Rules</span>
</button>
<div class="content" role="region" id="sectRules" aria-labledby="rules_list">
<h4>What rules must all visitors follow?</h4>
<ul class="list">
<li style="list-style-type:disc; border-top:0px; margin-bottom:0px; padding-bottom:0px; padding-top:10px; overflow:visible;">rule 1</li>
<li style="list-style-type:disc; border-top:0px; margin-bottom:0px; padding-bottom:0px; padding-top:10px; overflow:visible;">rule 2</li>
<li style="list-style-type:disc; border-top:0px; margin-bottom:0px; padding-bottom:0px; padding-top:10px; overflow:visible;">rule 3 etc..</li>
</ul>
</div>
</div>
相关的js是:
/* Generic Accordion */
$('.accordion .title').click(function() {
$(this).parent().parent().children('.content').toggle();
$(this).toggleClass('open');
$(this).hasClass("open") ? $(this).parent().attr("aria-expanded", "true") : $(this).parent().attr("aria-expanded", "false");
});
/* Adding support for keyboard */
$('.accordion').on('keydown', function(e) {
if (/^(13|32)$/.test(e.which)) {
e.preventDefault();
$(this).find('.title').click();
}
});
相关的CSS是:
.accordion + .content {
display: none;
margin-top: 10px;
padding: 10px;
}
.accordion + .content.open {
display: block;
background-color: white;
}
我很茫然,任何帮助将不胜感激。
【问题讨论】:
标签: jquery accessibility accordion wai-aria screen-readers