I'm working on making our accordions accessible with aria labels such as aria-expanded. I have the value of aria-expanded change correctly as the accordion trigger heading gets clicked or the 'return' button is pressed on the keyboard. For some reason though ChromeVox, which I'm using to test, will only say 'button collapsed' initially but doesn't say 'button expanded' once the value changes after a click.
I've looked at examples on other sites such as https://www.w3.org/TR/wai-aria-practices/examples/accordion/accordion.html and ChromeVox reads both states of aria-expanded correctly there, so I'm thinking it's something about how my code is structured that is preventing ChromeVox from announcing the 'expanded' state.
Here is an example of one accordion section:
<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>
The relevant js is:
/* 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();
}
});
The relevant CSS is :
.accordion + .content {
display: none;
margin-top: 10px;
padding: 10px;
}
.accordion + .content.open {
display: block;
background-color: white;
}
I'm at a loss, any help would be much appreciated.